Submission #123592

# Submission time Handle Problem Language Result Execution time Memory
123592 2019-07-01T17:47:31 Z MohamedAhmed04 Lightning Conductor (POI11_pio) C++14
81 / 100
1000 ms 8184 KB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#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]) ;
	for(int i = 0 ; i < n ; ++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) ;
		}
		for(int j = 1 ; i - (j-1) * (j-1) - 1 >= 0 ; ++j)
		{
			if(i - (j-1) * (j-1) - 1 < 0)
				break ;
			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

pio.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
 
pio.cpp: In function 'int main()':
pio.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n) ;
  ~~~~~^~~~~~~~~~~
pio.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d" , &arr[i]) ;
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 1016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 1444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 1400 KB Output is correct
2 Correct 56 ms 1400 KB Output is correct
3 Correct 113 ms 1660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 2040 KB Output is correct
2 Correct 110 ms 1912 KB Output is correct
3 Correct 113 ms 2552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 391 ms 4088 KB Output is correct
2 Correct 386 ms 4088 KB Output is correct
3 Correct 389 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 838 ms 7944 KB Output is correct
2 Correct 798 ms 6140 KB Output is correct
3 Correct 821 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 5880 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1066 ms 5808 KB Time limit exceeded
2 Halted 0 ms 0 KB -