Submission #718829

# Submission time Handle Problem Language Result Execution time Memory
718829 2023-04-05T00:35:00 Z Ahmed57 Lightning Conductor (POI11_pio) C++14
63 / 100
1000 ms 43908 KB
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")

#include <bits/stdc++.h>
using namespace std ;
int logg[500001];
int table[500001][20];
int qu(int l,int r){
    int ge = logg[r-l+1];
    return max(table[l][ge],table[r-(1<<ge)+1][ge]);
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;cin>>n;
    int arr[n];
    for(int i = 0;i<n;i++){
        cin>>arr[i];
        table[i][0] = arr[i];
    }
    logg[1] = 0;
    for(int i = 2;i<=n;i++)logg[i] = logg[i/2]+1;
    for(int j = 1;j<20;j++){
        for(int i = 0;i<n;i++){
            if(i+(1<<j)<=n){
                table[i][j] = max(table[i][j-1],table[i+(1<<(j-1))][j-1]);
            }
        }
    }
    for(int i = 0;i<n;i++){
        int st = i+1,len = 1;
        int all =arr[i];
        while(st<n){
            int en = min(n-1,i+(len*len));
            all = max(all,qu(st,en)+len);
            st = en+1;len++;
        }
        st = i-1;len = 1;
        while(st>=0){
            int en = max(0,i-(len*len));
            all = max(all,qu(en,st)+len);
            st = en-1;len++;
        }
        cout<<all-arr[i]<<"\n";
    }
    return 0 ;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 3124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 5100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 179 ms 6092 KB Output is correct
2 Correct 160 ms 6124 KB Output is correct
3 Correct 152 ms 6392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 472 ms 9216 KB Output is correct
2 Correct 445 ms 9100 KB Output is correct
3 Correct 414 ms 9760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1062 ms 20492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 31304 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1079 ms 43908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 43720 KB Time limit exceeded
2 Halted 0 ms 0 KB -