Submission #47370

# Submission time Handle Problem Language Result Execution time Memory
47370 2018-05-01T16:59:49 Z tieunhi Lightning Conductor (POI11_pio) C++14
81 / 100
1000 ms 22268 KB
#include <bits/stdc++.h>
#define pii pair<int, int>
#define mp make_pair
#define F first
#define S second
#define PB push_back
#define maxc 1000000007
#define N 510005
using namespace std;

int n, a[N], x2[N], res[N], lef[N], rig[N];

void inline MAX(int &A, int B) {A = max(A, B);}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("INP.TXT", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= sqrt(n) + 1; i++)
        x2[i] = i*i;

    for (int i = 1; i <= n; i++)
        lef[i] = max(a[i], lef[i-1]);
    for (int i = n; i >= 1; i--)
        rig[i] = max(a[i], rig[i+1]);
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; i - x2[j-1] - 1 > 0; j++)
            MAX(res[i], lef[i - x2[j-1] - 1] + j);
    }
    for (int i = n; i >= 1; i--)
    {
        for (int j = 1; i + x2[j-1] + 1 <= n; j++)
            MAX(res[i], rig[i + x2[j-1] + 1] + j);
    }
    for (int i = 1; i <= n; i++)
        if (res[i] <= a[i]) cout <<0<<'\n';
        else cout <<res[i] - a[i]<<'\n';

}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 50 ms 1904 KB Output is correct
2 Correct 45 ms 1904 KB Output is correct
3 Correct 53 ms 2156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 2684 KB Output is correct
2 Correct 92 ms 2684 KB Output is correct
3 Correct 99 ms 3136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 5288 KB Output is correct
2 Correct 334 ms 7164 KB Output is correct
3 Correct 312 ms 9204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 623 ms 13008 KB Output is correct
2 Correct 618 ms 14312 KB Output is correct
3 Correct 622 ms 18512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1036 ms 22268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1076 ms 22268 KB Time limit exceeded
2 Halted 0 ms 0 KB -