Submission #37665

#TimeUsernameProblemLanguageResultExecution timeMemory
37665szawinisLightning Conductor (POI11_pio)C++14
100 / 100
399 ms5932 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 5e5+1; int n, h[N], res[N]; void solve(int l, int r, int optL, int optR) { if(l > r) return; int mid = l+r >> 1, opt = optL; for(int i = optL; i <= min(optR, mid); i++) if(h[i] + sqrt(mid - i) > h[opt] + sqrt(mid - opt)) opt = i; res[mid] = max(h[opt] + (int) ceil(sqrt(mid - opt)) - h[mid], res[mid]); solve(l, mid-1, optL, opt); solve(mid+1, r, opt, optR); } int main() { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%d", &h[i]); solve(0, n-1, 0, n-1); reverse(h, h+n); reverse(res, res+n); solve(0, n-1, 0, n-1); reverse(h, h+n); reverse(res, res+n); for(int i = 0; i < n; i++) printf("%d\n", res[i]); }

Compilation message (stderr)

pio.cpp: In function 'void solve(int, int, int, int)':
pio.cpp:10:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l+r >> 1, opt = optL;
             ^
pio.cpp: In function 'int main()':
pio.cpp:20:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
pio.cpp:21:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < n; i++) scanf("%d", &h[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...
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...