Submission #123574

# Submission time Handle Problem Language Result Execution time Memory
123574 2019-07-01T17:02:30 Z MohamedAhmed04 Lightning Conductor (POI11_pio) C++14
72 / 100
376 ms 4624 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimization ("unroll-loops")
 
using namespace std ;
 
const int MAX = 3e5 + 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 21 ms 988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 1424 KB Output is correct
2 Correct 49 ms 1344 KB Output is correct
3 Correct 54 ms 1596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 1872 KB Output is correct
2 Correct 107 ms 1916 KB Output is correct
3 Correct 103 ms 2500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 4100 KB Output is correct
2 Correct 371 ms 3884 KB Output is correct
3 Correct 365 ms 4624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 47 ms 1500 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 49 ms 1528 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 47 ms 1528 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -