Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 완전탐색
- 구현
- 동적계획법
- Effective Java
- 그리디
- mst
- 시뮬레이션
- dfs
- 세그먼트 트리
- 스택
- swea
- 위상정렬
- 플로이드-와샬
- java
- 수학
- BFS
- 에라토스테네스의 체
- CS
- 프로그래머스
- 백트래킹
- 문자열
- 이분탐색
- 투 포인터
- 후니의 쉽게 쓴 시스코 네트워킹
- Kotlin
- 백준
- Network
- 유니온 파인드
- JUnit 5
- 알고리즘
Archives
반갑습니다!
[백준] 10973 이전 순열 본문
풀이
직접 구현해도 되지만 prev_permutation
STL을 사용해서 해결하였다.
코드
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
vector<int> ans(n);
bool first = true;
for (int i = 0; i < n; i++) {
cin >> ans[i];
if (i == 0) continue;
else if (ans[i] < ans[i - 1]) first = false;
}
if (first) cout << "-1\n";
else {
for (int i = 0; i < 1; i++)
prev_permutation(ans.begin(), ans.end());
for (int i = 0; i < n; i++)
cout << ans[i] << ' ';
cout << '\n';
}
return 0;
}
'알고리즘 문제 풀이' 카테고리의 다른 글
[백준] 1938 통나무 옮기기 (0) | 2020.04.23 |
---|---|
[백준] 2146 다리 만들기 (0) | 2020.04.23 |
[백준] 14425 문자열 집합 (0) | 2020.04.23 |
[프로그래머스] 자동완성 (0) | 2020.04.23 |
[백준] 5052 전화번호 목록 (0) | 2020.04.23 |