티스토리 뷰
문제링크 : https://www.acmicpc.net/problem/10973
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
int arr[10001];
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
for(int i=0; i<N; i++) cin >> arr[i];
if(prev_permutation(arr, arr+N))
{
for(int i=0; i<N; i++) cout << arr[i] << " ";
}
else cout << -1;
return 0;
}
[백준 10972번] 다음 순열 문제와 비슷한 유형이다.
여기서는 next_permutation 함수대신 prev_permutation 함수를 통해 간단히 해결이 가능하다.
'Problem Solving > 백준' 카테고리의 다른 글
| [백준 1052번] 물병 (C++) (0) | 2025.04.12 |
|---|---|
| [백준 11576번] Base Conversion (C++) (0) | 2025.04.12 |
| [백준 1850번] 최대공약수 (C++) (0) | 2025.04.10 |
| [백준 1016번] 제곱 ㄴㄴ 수 (C++) (0) | 2025.04.10 |
| [백준 10986번] 나머지 합 (C++) (0) | 2025.04.09 |