Submission #718839

# Submission time Handle Problem Language Result Execution time Memory
718839 2023-04-05T00:54:14 Z Ahmed57 Lightning Conductor (POI11_pio) C++14
91 / 100
370 ms 13120 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long
long long dp[500001];
long long arr[500001];
void dc(int l,int r,int optl,int optr){
    if(l>r)return ;
    int mid = (l+r)/2;
    long long best = optl;
    for(int cut = optl;cut<=min(mid,optr);cut++){
        if(arr[best]+sqrt(abs(mid-best))<arr[cut]+sqrt(abs(mid-cut))){
            best = cut;
        }
    }
    dp[mid]=max(dp[mid],arr[best]+(int)ceil(sqrt(abs(mid-best)))-arr[mid]);
    int opt = best;
    dc(l,mid-1,optl,opt);
    dc(mid+1,r,opt,optr);
}
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    for(int i = 1;i<=n;i++){
        cin>>arr[i];
    }
    for(int i = 0;i<=n;i++)dp[i] = 0;
    dc(1,n,0,n-1);
    reverse(arr+1,arr+n+1);
    reverse(dp+1,dp+n+1);
    dc(1,n,0,n-1);
    reverse(dp+1,dp+n+1);
    reverse(arr+1,arr+n+1);
    for(int i = 1;i<=n;i++){
        cout<<dp[i]<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 18 ms 1056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1544 KB Output is correct
2 Incorrect 36 ms 1484 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 2236 KB Output is correct
2 Correct 69 ms 2240 KB Output is correct
3 Correct 61 ms 2760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 160 ms 4928 KB Output is correct
2 Correct 156 ms 4812 KB Output is correct
3 Correct 148 ms 5492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 247 ms 9272 KB Output is correct
2 Correct 243 ms 7220 KB Output is correct
3 Correct 239 ms 9268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 345 ms 13060 KB Output is correct
2 Correct 344 ms 10048 KB Output is correct
3 Correct 334 ms 13116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 342 ms 10632 KB Output is correct
2 Correct 370 ms 10048 KB Output is correct
3 Correct 348 ms 13120 KB Output is correct