백준/실버

[백준 10973번] 이전 순열 (C++)

게임개발기원 2025. 4. 11. 23:20

문제링크 : 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 함수를 통해 간단히 해결이 가능하다.