Submission #158416

# Submission time Handle Problem Language Result Execution time Memory
158416 2019-10-17T02:52:19 Z luciocf Lightning Conductor (POI11_pio) C++14
63 / 100
1000 ms 50556 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 5e5+10;
const int maxl = 21;

int n;
int a[maxn];

int tab[maxn][maxl];
int lg[maxn];

void build(void)
{
	lg[1] = 0;
	for (int i = 2; i < maxn; i++)
		lg[i] = lg[i/2]+1;

	for (int i = 1; i <= n; i++)
		tab[i][0] = a[i];

	for (int j = 1; j < maxl; j++)
		for (int i = 1; i + (1<<j) <= n+1; i++)
			tab[i][j] = max(tab[i][j-1], tab[i+(1<<(j-1))][j-1]);
}

int mx(int l, int r)
{
	int j = lg[r-l+1];

	return max(tab[l][j],tab[r-(1<<j)+1][j]);
}

int main(void)
{
	scanf("%d", &n);

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);

	build();

	for (int i = 1; i <= n; i++)
	{
		int k = 0;

		for (int d = 1; (d-1)*(d-1) <= n; d++)
		{
			int l = max(1, i - d*d);
			int r = min(i-1, i - d*d + 2*d - 2);

			if (l > r) continue;

			k = max(k, mx(l, r) + d);
		}

		for (int d = 1; (d-1)*(d-1) <= n; d++)
		{
			int l = max(i+1, d*d - 2*d + i + 2);
			int r = min(n, i + d*d);

			if (l > r) continue;

			k = max(k, mx(l, r) + d);
		}

		printf("%d\n", max(0, k-a[i]));
	}
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:37: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", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 5544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 7604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 285 ms 8824 KB Output is correct
2 Correct 288 ms 8280 KB Output is correct
3 Correct 289 ms 8940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 566 ms 12408 KB Output is correct
2 Correct 565 ms 12100 KB Output is correct
3 Correct 556 ms 12416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 24744 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1078 ms 36348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1072 ms 50556 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1081 ms 50344 KB Time limit exceeded
2 Halted 0 ms 0 KB -