# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
37665 | szawinis | Lightning Conductor (POI11_pio) | C++14 | 399 ms | 5932 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |