백준 알고리즘 10972번 : 다음 순열

Zoo Da·2021년 11월 16일
0

백준 알고리즘

목록 보기
256/337
post-thumbnail

링크

https://www.acmicpc.net/problem/10972

sol1) STL

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

int32_t main() {
  fastio;
  int n; cin >> n;
  vector<int> v(n);
  for(int i = 0; i < n; i++) cin >> v[i];
  if(next_permutation(v.begin(), v.end())){
    for(auto&c : v) cout << c << ' ';
    cout << "\n";
  }
  else cout << -1 << "\n";
  return 0;
}

순열 stl인 next_permutation을 활용해주면 됩니다.

profile
메모장 겸 블로그

0개의 댓글