Submission #1028021

#TimeUsernameProblemLanguageResultExecution timeMemory
1028021rsinventorGlobal Warming (NOI13_gw)C++17
0 / 40
5 ms912 KiB
#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++; 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; }

Compilation message (stderr)

gw.cpp: In function 'int main()':
gw.cpp:9:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     freopen("warming.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
gw.cpp:10:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     freopen("warming.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...