Submission #586137

#TimeUsernameProblemLanguageResultExecution timeMemory
586137hibikiGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++11
0 / 100
1 ms312 KiB
#include<bits/stdc++.h> using namespace std; int n, l, r, mx, po, ans; int a[200005]; int main() { mx = 0, po = -1, ans = 0; scanf("%d",&n); for(int i = 0; i < n; i++) { scanf("%d",&a[i]); if(a[i] > mx) { mx = a[i]; po = i; } } l = max(po - 1, 0); r = min(po + 1, n - 1); if(l != po && a[l] == a[po]) ans++, a[po]++; if(r != po && a[r] == a[po]) ans++, a[po]++; while(l > 0 || r < n - 1) { int difl = 1e9, difr = 1e9; if(l > 0) difl = max(0, a[l - 1] - a[l] + 1); if(r < n - 1) difr = max(0, a[r + 1] - a[r] + 1); if(difl < difr) { ans += difl; a[r] += difl; l--; } else { ans += difr; a[l] += difr; r++; } } printf("%d\n",ans); return 0; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
Main.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...