Submission #235872

# Submission time Handle Problem Language Result Execution time Memory
235872 2020-05-30T08:46:35 Z PeppaPig Lightning Conductor (POI11_pio) C++14
100 / 100
154 ms 15992 KB
#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

pio.cpp: In function 'int main()':
pio.cpp:10:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
pio.cpp:11:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i = 1; i <= n; i++) scanf("%d", A + i);
                                 ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 2048 KB Output is correct
2 Correct 21 ms 1536 KB Output is correct
3 Correct 21 ms 2048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2936 KB Output is correct
2 Correct 29 ms 2808 KB Output is correct
3 Correct 30 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 6392 KB Output is correct
2 Correct 57 ms 6008 KB Output is correct
3 Correct 62 ms 6008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 11384 KB Output is correct
2 Correct 97 ms 9336 KB Output is correct
3 Correct 101 ms 9976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 15992 KB Output is correct
2 Correct 129 ms 13176 KB Output is correct
3 Correct 140 ms 14072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 141 ms 13560 KB Output is correct
2 Correct 144 ms 13152 KB Output is correct
3 Correct 137 ms 14072 KB Output is correct