Submission #867864

# Submission time Handle Problem Language Result Execution time Memory
867864 2023-10-29T16:06:35 Z ttamx Lightning Conductor (POI11_pio) C++14
100 / 100
195 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];

double calc(int i,int j){
    return h[j]-h[i]+sqrt(i-j);
}

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(calc(mid,i)>calc(mid,opt))opt=i;
    dp[mid]=max(dp[mid],(int)ceil(calc(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 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 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 2956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 2908 KB Output is correct
2 Correct 18 ms 2904 KB Output is correct
3 Correct 20 ms 3164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3164 KB Output is correct
2 Correct 33 ms 3156 KB Output is correct
3 Correct 36 ms 3632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 4312 KB Output is correct
2 Correct 89 ms 4068 KB Output is correct
3 Correct 75 ms 4688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 7112 KB Output is correct
2 Correct 124 ms 5056 KB Output is correct
3 Correct 118 ms 7116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 195 ms 9300 KB Output is correct
2 Correct 177 ms 6156 KB Output is correct
3 Correct 172 ms 9212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 177 ms 6740 KB Output is correct
2 Correct 174 ms 6224 KB Output is correct
3 Correct 168 ms 9208 KB Output is correct