Submission #544785

# Submission time Handle Problem Language Result Execution time Memory
544785 2022-04-02T16:45:47 Z rainboy Teams (CEOI11_tea) C
100 / 100
702 ms 47248 KB
#include <stdio.h>
#include <string.h>

#define N	1000000

int max(int a, int b) { return a > b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int *xx;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;
		
		while (j < k)
			if (xx[ii[j]] == xx[i_])
				j++;
			else if (xx[ii[j]] < xx[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

int ii_[N + 1], dp[N + 1], pp[N + 1], ll[N + 1], n;

int solve(int s) {
	static int prev[N + 1];
	static char ok[N + 1];
	int i, l;

	memset(prev, -1, (n + 1) * sizeof *prev);
	memset(ok, 0, (n + 1) * sizeof *ok);
	memset(pp, -1, (n + 1) * sizeof *pp);
	ok[0] = 1;
	i = 0;
	while (i < n && ll[ii_[i]] < 0)
		i++;
	for (l = 0; l <= n; l++) {
		if (ok[l])
			prev[dp[l]] = l;
		while (i < n && ll[ii_[i]] == l) {
			int p = prev[dp[ii_[i]] - 1];

			if (p != -1 && ii_[i] - p <= s)
				ok[ii_[i]] = 1, pp[ii_[i]] = p;
			i++;
		}
	}
	return ok[n];
}

int main() {
	static int aa[N], ii[N], dq[N + 1];
	int h, i, j, lower, upper;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		ii[i] = i;
	}
	xx = aa, sort(ii, 0, n);
	dp[0] = dq[0] = 0;
	for (i = 1; i <= n; i++) {
		ll[i] = i - aa[ii[i - 1]];
		dp[i] = ll[i] < 0 ? -1 : dq[ll[i]] + 1;
		dq[i] = max(dq[i - 1], dp[i]);
		ii_[i - 1] = i;
	}
	xx = ll, sort(ii_, 0, n);
	lower = 0, upper = n;
	while (upper - lower > 1) {
		int s = (lower + upper) / 2;

		if (solve(s))
			upper = s;
		else
			lower = s;
	}
	solve(upper);
	printf("%d\n", dp[n]);
	for (j = n; j > 0; j = i) {
		i = pp[j];
		printf("%d", j - i);
		for (h = i; h < j; h++)
			printf(" %d", ii[h] + 1);
		printf("\n");
	}
	return 0;
}

Compilation message

tea.c: In function 'main':
tea.c:67:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
tea.c:69:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 476 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
3 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 472 KB Output is correct
2 Correct 2 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 3836 KB Output is correct
2 Correct 41 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4300 KB Output is correct
2 Correct 39 ms 3384 KB Output is correct
3 Correct 40 ms 4268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 372 ms 33280 KB Output is correct
2 Correct 335 ms 31860 KB Output is correct
3 Correct 391 ms 33996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 542 ms 45304 KB Output is correct
2 Correct 536 ms 43352 KB Output is correct
3 Correct 501 ms 42384 KB Output is correct
4 Correct 515 ms 39596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 537 ms 46256 KB Output is correct
2 Correct 350 ms 47248 KB Output is correct
3 Correct 477 ms 43388 KB Output is correct
4 Correct 702 ms 45176 KB Output is correct