Submission #123564

# Submission time Handle Problem Language Result Execution time Memory
123564 2019-07-01T15:44:43 Z MohamedAhmed04 Lightning Conductor (POI11_pio) C++14
63 / 100
1000 ms 23336 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];

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 main()
{
	scanf("%d" , &n) ;
	for(int i = 0 ; i < n ; ++i)
		scanf("%d" , &arr[i]) ;
	sparse_table() ;
	for(int i = 0 ; i < n ; ++i)
	{
		int ans = 0 ;
		for(int j = 1 ; j < n ; ++j)
		{
			int l = i + (j-1) * (j-1) + 1 ;
			int r = i + (j+1) * (j+1) - 1 ;
			r = min(r , n-1) ;
			if(l >= n)
				break ;
			ans = max(ans , RMQ(l , r) - arr[i] + j) ;
		}
		for(int j = 1 ; j < n ; ++j)
		{
			int r = i - (j-1) * (j-1) - 1 ;
			int l = i - (j+1) * (j+1) + 1 ;
			l = max(l , 0) ;
			if(r < 0)
				break ;
			ans = max(ans , RMQ(l , r) - arr[i] + j) ;
		}
		printf("%d\n" , ans) ;
	}
	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:38:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n) ;
  ~~~~~^~~~~~~~~~~
pio.cpp:40: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 3 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 4572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 185 ms 6676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 271 ms 8056 KB Output is correct
2 Correct 273 ms 7928 KB Output is correct
3 Correct 279 ms 8184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 521 ms 11320 KB Output is correct
2 Correct 520 ms 11128 KB Output is correct
3 Correct 538 ms 11704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 23336 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 58 ms 1656 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 58 ms 1696 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 50 ms 1656 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -