Submission #123553

# Submission time Handle Problem Language Result Execution time Memory
123553 2019-07-01T15:24:45 Z MohamedAhmed04 Lightning Conductor (POI11_pio) C++14
63 / 100
1000 ms 24016 KB
#include <bits/stdc++.h>

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: In function 'int main()':
pio.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d" , &n) ;
  ~~~~~^~~~~~~~~~~
pio.cpp:38: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 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 7224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 8440 KB Output is correct
2 Correct 277 ms 8056 KB Output is correct
3 Correct 276 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 532 ms 11768 KB Output is correct
2 Correct 526 ms 12152 KB Output is correct
3 Correct 507 ms 12348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 24016 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 58 ms 2040 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 58 ms 2040 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 51 ms 2040 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -