Submission #226373

# Submission time Handle Problem Language Result Execution time Memory
226373 2020-04-23T14:59:53 Z DodgeBallMan Lightning Conductor (POI11_pio) C++14
100 / 100
154 ms 15992 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 5e5 + 10;
int n, mx = -1, h[N], mxl[N], mxr[N];
int main()
{
    scanf("%d",&n);
    for( int i = 1 ; i <= n ; i++ ) scanf("%d",&h[i]);
    for( int i = 1 ; i <= n ; i++ ) {
        mxl[i] = max( mxl[i], h[i] );
        if( h[i] <= mx ) continue ;
        mx = max( mx, h[i] );
        for( int d = 0 ; i + d*d + 1 <= n ; d++ ) {
            int pos = i + d*d + 1;
            mxl[pos] = max( mxl[pos], h[i] + d + 1 );
        }
    }
    mx = -1;
    for( int i = n ; i >= 1 ; i-- ) {
        mxr[i] = max( mxr[i], h[i] );
        if( h[i] <= mx ) continue ;
        mx = max( mx, h[i] );
        for( int d = 0; i - d*d - 1 > 0 ; d++ ) {
            int pos = i - d*d - 1;
            mxr[pos] = max( mxr[pos], h[i] + d + 1 );
        }
    }
    for( int i = 1 ; i <= n ; i++ ) mxl[i] = max( mxl[i], mxl[i-1] );
    for( int i = n ; i >= 1 ; i-- ) mxr[i] = max( mxr[i], mxr[i+1] );
    for( int i = 1 ; i <= n ; i++ ) printf("%d\n",max( mxl[i], mxr[i] ) - h[i] );
    return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&n);
     ~~~~~^~~~~~~~~
pio.cpp:10:42: 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",&h[i]);
                                     ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 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 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 1920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2048 KB Output is correct
2 Correct 17 ms 1536 KB Output is correct
3 Correct 21 ms 2040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2936 KB Output is correct
2 Correct 28 ms 2808 KB Output is correct
3 Correct 30 ms 3064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 73 ms 6396 KB Output is correct
2 Correct 56 ms 5984 KB Output is correct
3 Correct 58 ms 6008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 11428 KB Output is correct
2 Correct 84 ms 9340 KB Output is correct
3 Correct 98 ms 9976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 154 ms 15992 KB Output is correct
2 Correct 116 ms 13048 KB Output is correct
3 Correct 136 ms 14072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 13688 KB Output is correct
2 Correct 127 ms 13176 KB Output is correct
3 Correct 134 ms 14136 KB Output is correct