Submission #1029456

#TimeUsernameProblemLanguageResultExecution timeMemory
1029456rsinventorGlobal Warming (NOI13_gw)C++17
0 / 40
173 ms29508 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++; } vector<bool> visited(n); mx_islands = max(mx_islands, islands); for(int i = 0; i < sh2.size(); i++) { int s = sh2[i].second; islands++; visited[s] = true; if(visited[s+1]) { islands--; } if(visited[s-1]) { islands--; } if(i==n-1 || sh2[i].first!=sh2[i+1].first) { mx_islands = max(mx_islands, islands); } } cout << mx_islands << endl; return 0; }

Compilation message (stderr)

gw.cpp: In function 'int main()':
gw.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i = 0; i < sh2.size(); i++) {
      |                    ~~^~~~~~~~~~~~
#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...