Submission #123582

# Submission time Handle Problem Language Result Execution time Memory
123582 2019-07-01T17:18:38 Z MohamedAhmed04 Lightning Conductor (POI11_pio) C++14
81 / 100
1000 ms 8172 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimization ("unroll-loops")
 
using namespace std ;
 
const int MAX = 5e5 + 5 ;
 
int arr[MAX] , st[MAX][23] , lg[MAX] , pref[MAX] , suff[MAX];
 
int n ;
 
/*void sparse_table()
{
	lg[1] = 0 ;
	for(int i = 2 ; i < MAX ; ++i)
		lg[i] = lg[i / 2] + 1 ;
	for(int i = 0 ; i < n ; ++i)
		st[i][0] = arr[i] ;
	for(int j = 1 ; j <= lg[n] ; ++j)
	{
		for(int i = 0 ; i + (1 << j) <= n ; ++i)
		{
			st[i][j] = max(st[i][j-1] , st[i + (1 << (j-1))][j-1]) ;
		}
	}
	return ;
}
 
int RMQ(int l , int r)
{
	int j = lg[r-l+1] ;
	return max(st[l][j] , st[r - (1 << j) + 1][j]) ;
}*/
 
int readint()
{
	char c = getchar() ;
	while(true)
	{
		if(c >= '0' && c <= '9')
			break ;
		c = getchar() ;
	}
	int x = (c - '0') ;
	c = getchar() ;
	while(true)
	{
		if(c < '0' || c > '9')
			break ;
		x = x * 10 + (c - '0') ;
        c = getchar() ;
	}
	return x ;
}
 
int main()
{
	n = readint() ;
	for(int i = 0 ; i < n ; ++i)
		arr[i] = readint() ;
	for(int i = 0 ; i < n ; ++i)
	{
		for(int j = 1 ; j < n ; ++j)
		{
			if(i + (j-1) * (j-1) + 1 >= n)
				break ;
			pref[i + (j-1) * (j-1) + 1] = max(pref[i + (j-1) * (j-1) + 1] , arr[i] + j) ;
		}
		for(int j = 1 ; j < n ; ++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")
# 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 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 1400 KB Output is correct
2 Correct 49 ms 1400 KB Output is correct
3 Correct 54 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 1912 KB Output is correct
2 Correct 108 ms 1992 KB Output is correct
3 Correct 104 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 4212 KB Output is correct
2 Correct 377 ms 3952 KB Output is correct
3 Correct 371 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 809 ms 8172 KB Output is correct
2 Correct 792 ms 5992 KB Output is correct
3 Correct 779 ms 8144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 5840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1071 ms 5644 KB Time limit exceeded
2 Halted 0 ms 0 KB -