답안 #1025870

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025870 2024-07-17T10:53:25 Z rsinventor 지구 온난화 (NOI13_gw) C++17
0 / 40
188 ms 23932 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector <vector<ll>> vvi;
typedef vector<bool> vb;
typedef vector <vector<bool>> vvb;
typedef vector <string> vs;
typedef vector<char> vc;
typedef vector <vector<char>> vvc;
typedef pair<ll, ll> pii;
typedef vector <pii> vpii;

#define all(a) (a).begin(), (a).end()
#define pb push_back
#define endl "\n"

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n;
    cin >> n;
    vi h(n);
//    set<ll> sh;
    vpii sh2(n);
    for(ll i = 0; i < n; i++) {
        cin >> h[i];
        sh2[i].first = h[i];
        sh2[i].second = i;
//        sh.insert(h[i]);
    }
    sort(all(sh2));
    
    ll mx_islands = 0;
//    sh.insert(0);
//    for(ll v : sh) {
//        ll islands = 0;
//        for(ll i = 0; i < n; i++) {
//            if(max(0, h[i]-v)>0 && (i==0 || max(0, h[i-1]-v)==0)) islands++;
//        }
//        mx_islands = max(mx_islands, islands);
//    }
    
    ll islands = 0;
    mx_islands = 0;
    for(ll i = 0; i < n; i++) {
        if(max(0LL, h[i])>0 && (i==0 || max(0LL, h[i-1])==0)) islands++;
    }
    mx_islands = max(mx_islands, islands);
    for(ll i = 0; i < n; i++) {
        if(sh2[i].first==sh2[i-1].first && abs(sh2[i].second-sh2[i-1].second)<=1) continue;
        ll s = sh2[i].second;
        ll 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++;
                mx_islands = max(mx_islands, islands);
            } else if(h[s-1]<h[s] && h[e+1]<h[e]) {
                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 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 2648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 2652 KB Output is correct
2 Incorrect 15 ms 2652 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 188 ms 23932 KB Output is correct
2 Correct 180 ms 23900 KB Output is correct
3 Correct 165 ms 23896 KB Output is correct
4 Correct 173 ms 23896 KB Output is correct
5 Incorrect 180 ms 23900 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 23896 KB Output is correct
2 Correct 162 ms 23928 KB Output is correct
3 Correct 159 ms 23932 KB Output is correct
4 Incorrect 174 ms 23900 KB Output isn't correct
5 Halted 0 ms 0 KB -