Submission #867859

# Submission time Handle Problem Language Result Execution time Memory
867859 2023-10-29T16:03:51 Z ttamx Lightning Conductor (POI11_pio) C++14
100 / 100
184 ms 12112 KB
#include<bits/stdc++.h>

using namespace std;

const int N=5e5+5;
const int inf=1e9;

int n;
int h[N],dp[N];
void solve(int l,int r,int optl,int optr){
    if(l>r)return;
    int mid=(l+r)/2;
    int opt=optl;
    for(int i=optl;i<=min(mid,optr);i++)if(h[i]+sqrt(mid-i)>h[opt]+sqrt(mid-opt))opt=i;
    dp[mid]=max(dp[mid],h[opt]-h[mid]+(int)ceil(sqrt(mid-opt)));
    solve(l,mid-1,optl,opt);
    solve(mid+1,r,opt,optr);
}

int main(){
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n;
    for(int i=1;i<=n;i++)cin >> h[i];
    for(int t=0;t<2;t++){
        solve(1,n,1,n);
        reverse(h+1,h+n+1);
        reverse(dp+1,dp+n+1);
    }
    for(int i=1;i<=n;i++)cout << dp[i] << "\n"; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 2908 KB Output is correct
2 Correct 19 ms 2908 KB Output is correct
3 Correct 20 ms 3172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 3056 KB Output is correct
2 Correct 34 ms 3152 KB Output is correct
3 Correct 33 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 78 ms 4332 KB Output is correct
2 Correct 82 ms 4180 KB Output is correct
3 Correct 86 ms 4692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 7128 KB Output is correct
2 Correct 120 ms 4948 KB Output is correct
3 Correct 116 ms 7096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 9216 KB Output is correct
2 Correct 171 ms 6224 KB Output is correct
3 Correct 166 ms 9300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 182 ms 6648 KB Output is correct
2 Correct 176 ms 11088 KB Output is correct
3 Correct 171 ms 12112 KB Output is correct