# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
123606 | MohamedAhmed04 | Lightning Conductor (POI11_pio) | C++14 | 161 ms | 14072 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std ;
const int MAX = 5e5 + 5 ;
int arr[MAX] , pref[MAX] , suff[MAX];
int n ;
int main()
{
scanf("%d" , &n) ;
for(int i = 0 ; i < n ; ++i)
scanf("%d" , &arr[i]) ;
int MAX = -1 ;
for(int i = 0 ; i < n ; ++i)
{
if(arr[i] <= MAX)
continue ;
MAX = arr[i] ;
for(int j = 1 ; i + (j-1) * (j-1) + 1 < n ; ++j)
{
pref[i + (j-1) * (j-1) + 1] = max(pref[i + (j-1) * (j-1) + 1] , arr[i] + j) ;
}
}
MAX = -1 ;
for(int i = n-1 ; i >= 0 ; --i)
{
if(arr[i] <= MAX)
continue ;
MAX = arr[i] ;
for(int j = 1 ; i - (j-1) * (j-1) - 1 >= 0 ; ++j)
{
suff[i - (j-1) * (j-1) - 1] = max(suff[i - (j-1) * (j-1) - 1] , arr[i] + j) ;
}
}
for(int i = 1 ; i < n ; ++i)
pref[i] = max(pref[i] , pref[i-1]) ;
for(int i = n-2 ; i >= 0 ; --i)
suff[i] = max(suff[i] , suff[i+1]) ;
for(int i = 0 ; i < n ; ++i)
printf("%d\n" , max(0 , max(pref[i] , suff[i]) - arr[i])) ;
return 0 ;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |