Submission #867860

# Submission time Handle Problem Language Result Execution time Memory
867860 2023-10-29T16:04:27 Z ttamx Lightning Conductor (POI11_pio) C++14
100 / 100
188 ms 9300 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[mid]>h[opt]+sqrt(mid-opt)-h[mid])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 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 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 17 ms 2952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2908 KB Output is correct
2 Correct 19 ms 2904 KB Output is correct
3 Correct 21 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3160 KB Output is correct
2 Correct 33 ms 3156 KB Output is correct
3 Correct 32 ms 3568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 4180 KB Output is correct
2 Correct 78 ms 4060 KB Output is correct
3 Correct 75 ms 4828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 124 ms 7252 KB Output is correct
2 Correct 124 ms 5052 KB Output is correct
3 Correct 118 ms 7248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 9296 KB Output is correct
2 Correct 188 ms 6228 KB Output is correct
3 Correct 170 ms 9296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 180 ms 6832 KB Output is correct
2 Correct 175 ms 6224 KB Output is correct
3 Correct 179 ms 9300 KB Output is correct