PS

BOJ 28136 : 원, 탁!

lickelon 2025. 1. 2. 23:21
  • 문제 링크 : 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