답안 #1029454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029454 2024-07-20T22:16:47 Z rsinventor 지구 온난화 (NOI13_gw) C++17
23 / 40
176 ms 12124 KB
#include <bits/stdc++.h>

using namespace std;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

//    freopen("warming.in", "r", stdin);
//    freopen("warming.out", "w", stdout);

    int n;
    cin >> n;
    int h[n];
    vector<pair<int, int>> sh2(n);
    for(int i = 0; i < n; i++) {
        cin >> h[i];
        sh2[i].first = h[i];
        sh2[i].second = i;
    }
    sort(sh2.begin(), sh2.end());

    int mx_islands = 0;
    int islands = 0;
    for(int i = 0; i < n; i++) {
        if(max(0, h[i])>0 && (i==0 || max(0, h[i-1])==0)) islands++;
    }
    mx_islands = max(mx_islands, islands);
    for(int i = 0; i < n; i++) {
        if(sh2[i].first==sh2[i-1].first && abs(sh2[i].second-sh2[i-1].second)<=1) continue;
        int s = sh2[i].second;
        int e = sh2[i].second;
        while(e+1<n && h[e] == h[e+1]) e++;
        if(s==0 && e == n-1) {
            islands = 0;
        } else if(s==0 && h[e+1]<h[s]) {
            islands--;
        } else if(e==n-1 && h[s-1]<h[e]) {
            islands--;
        } else {
            if(h[s-1]>h[s] && h[e+1]>h[e]) {
                islands++;
            } else if(h[s-1]<h[s] && h[e+1]<h[e]) {
                islands--;
            }
        }
        if(h[e+1]!=h[e] || e==n-1) {
            mx_islands = max(mx_islands, islands);
        }
    }

    cout << mx_islands << endl;


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 1640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1628 KB Output is correct
2 Correct 11 ms 1644 KB Output is correct
3 Correct 16 ms 1628 KB Output is correct
4 Correct 19 ms 1628 KB Output is correct
5 Correct 13 ms 1640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 12124 KB Output is correct
2 Correct 145 ms 12120 KB Output is correct
3 Correct 145 ms 12120 KB Output is correct
4 Correct 149 ms 12124 KB Output is correct
5 Correct 157 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 176 ms 12124 KB Output is correct
2 Correct 156 ms 12124 KB Output is correct
3 Correct 158 ms 12120 KB Output is correct
4 Incorrect 136 ms 12124 KB Output isn't correct
5 Halted 0 ms 0 KB -