- 문제 링크 : boj.kr/28136
- 난이도 : S5
- 태그 : 그리디
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<int> arr(n);
for(auto &e : arr) cin >> e;
arr.push_back(*arr.begin());
int ans = 0;
for(int i = 0; i < n; i++) {
if(arr[i+1] <= arr[i]) ans++;
}
cout << ans;
return 0;
}
풀이
어떤 원소 사이를 끊는 것은 다른 원소들에 영향을 주지 않는다.
따라서 오름차순이 아닌 원소 사이만 끊는 것이 최적이다.
728x90
'PS' 카테고리의 다른 글
BOJ 31908 : 커플링 매치 (1) | 2025.01.04 |
---|---|
BOJ 10799 : 쇠막대기 (0) | 2025.01.03 |
BOJ 11722 : 가장 긴 감소하는 부분 수열 (0) | 2025.01.02 |
BOJ 3986 : 좋은 단어 (0) | 2024.12.31 |
BOJ 10816 : 숫자 카드 2 (0) | 2024.12.30 |