Submission #516317

#TimeUsernameProblemLanguageResultExecution timeMemory
516317JomnoiGlobal Warming (NOI13_gw)C++17
23 / 40
270 ms22524 KiB
#include <bits/stdc++.h> #define DEBUG 0 using namespace std; const int N = 1e6 + 10; int parent[N]; bool appeared[N]; int root(int u) { if(u == parent[u]) { return u; } return parent[u] = root(parent[u]); } int main() { int n; scanf(" %d", &n); for(int i = 1; i <= n; i++) { parent[i] = i; } vector <pair <int, int>> vec; for(int i = 1; i <= n; i++) { int h; scanf(" %d", &h); vec.emplace_back(h, i); } sort(vec.rbegin(), vec.rend()); int cmp = 0, ans = 0; for(auto [h, i] : vec) { cmp++; appeared[i] = true; if(appeared[i - 1] == true) { cmp--; parent[root(i)] = root(i - 1); } if(appeared[i + 1] == true) { cmp--; parent[root(i)] = root(i + 1); } ans = max(ans, cmp); } printf("%d", ans); return 0; }

Compilation message (stderr)

gw.cpp: In function 'int main()':
gw.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf(" %d", &n);
      |     ~~~~~^~~~~~~~~~~
gw.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf(" %d", &h);
      |         ~~~~~^~~~~~~~~~~
#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...