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
- BFS
- 알고리즘
- 플로이드-와샬
- 수학
- 유니온 파인드
- Kotlin
- mst
- 완전탐색
- Effective Java
- 백준
- 구현
- java
- 프로그래머스
- 세그먼트 트리
- CS
- 스택
- 그리디
- 문자열
- 시뮬레이션
- 동적계획법
- JUnit 5
- 이분탐색
- 투 포인터
- 에라토스테네스의 체
- 위상정렬
- 백트래킹
- dfs
- swea
- 후니의 쉽게 쓴 시스코 네트워킹
- Network
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 |