# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
235872 | PeppaPig | Lightning Conductor (POI11_pio) | C++14 | 154 ms | 15992 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;
const int N = 5e5+5;
int n, A[N], pre[N], suf[N];
int main() {
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d", A + i);
for(int i = 1, mx = -1; i <= n; i++) {
if(A[i] <= mx) continue;
mx = max(mx, A[i]);
for(int j = 0; i + j * j + 1 <= n; j++)
pre[i + j * j + 1] = max(pre[i + j * j + 1], A[i] + j + 1);
}
for(int i = n, mx = -1; i; i--) {
if(A[i] <= mx) continue;
mx = max(mx, A[i]);
for(int j = 0; i - j * j - 1 > 0; j++)
suf[i - j * j - 1] = max(suf[i - j * j - 1], A[i] + j + 1);
}
for(int i = 1; i <= n; i++) pre[i] = max(pre[i], pre[i - 1]);
for(int i = n; i; i--) suf[i] = max(suf[i], suf[i + 1]);
for(int i = 1; i <= n; i++)
printf("%d\n", max(0, max(pre[i], suf[i]) - A[i]));
return 0;
}
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... |