Submission #718835

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

using namespace std;
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]+(long long)ceil(sqrt(mid-best)));
    int opt = best;
    dc(l,mid-1,optl,opt);
    dc(mid+1,r,opt,optr);
}
int 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]-arr[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 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 1072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 1592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 1576 KB Output is correct
2 Incorrect 37 ms 1572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 65 ms 2224 KB Output is correct
2 Correct 61 ms 2172 KB Output is correct
3 Correct 52 ms 2740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 4916 KB Output is correct
2 Correct 139 ms 4752 KB Output is correct
3 Correct 124 ms 5408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 248 ms 9168 KB Output is correct
2 Correct 224 ms 7244 KB Output is correct
3 Correct 197 ms 9280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 338 ms 13020 KB Output is correct
2 Correct 341 ms 10120 KB Output is correct
3 Correct 271 ms 13072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 341 ms 10540 KB Output is correct
2 Correct 345 ms 14920 KB Output is correct
3 Correct 270 ms 15936 KB Output is correct