Submission #817121

# Submission time Handle Problem Language Result Execution time Memory
817121 2023-08-09T09:40:11 Z rainboy Cell Automaton (JOI23_cell) C
24 / 100
422 ms 128872 KB
#include <stdio.h>

#define N	100000
#define X	2000
#define T	1000

int min(int a, int b) { return a < b ? a : b; }

unsigned int Z = 12345;

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

int xx[N], yy[N];

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 main() {
	static int ii[N], dd[X * 2 + 1][X * 2 + 1], nn[T + 1];
	int n, q, i, j, x, y, t, subtask;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	subtask = 3;
	if (q != 1)
		subtask = 2;
	for (i = 0; i < n; i++)
		if (xx[i] != yy[i]) {
			subtask = 2;
			break;
		}
	if (subtask == 2) {
		for (x = 0; x <= X * 2; x++)
			for (y = 0; y <= X * 2; y++)
				dd[x][y] = T + 1;
		for (i = 0; i < n; i++)
			dd[X + xx[i]][X + yy[i]] = 0;
		for (x = 0; x <= X * 2; x++) {
			for (y = 1; y <= X * 2; y++)
				dd[x][y] = min(dd[x][y], dd[x][y - 1] + 1);
			for (y = X * 2 - 1; y >= 0; y--)
				dd[x][y] = min(dd[x][y], dd[x][y + 1] + 1);
		}
		for (y = 0; y <= X * 2; y++) {
			for (x = 1; x <= X * 2; x++)
				dd[x][y] = min(dd[x][y], dd[x - 1][y] + 1);
			for (x = X * 2 - 1; x >= 0; x--)
				dd[x][y] = min(dd[x][y], dd[x + 1][y] + 1);
		}
		for (x = 0; x <= X * 2; x++)
			for (y = 0; y <= X * 2; y++)
				if (dd[x][y] <= T)
					nn[dd[x][y]]++;
		while (q--) {
			scanf("%d", &t);
			printf("%d\n", nn[t]);
		}
	} else {
		for (i = 0; i < n; i++)
			ii[i] = i;
		sort(ii, 0, n);
		while (q--) {
			long long ans;

			scanf("%d", &t);
			if (t == 0)
				printf("%d\n", n);
			else {
				ans = 0;
				for (i = 0; i < n; i = j) {
					j = i + 1;
					while (j < n && xx[ii[j]] - xx[ii[j - 1]] <= t)
						j++;
					ans += ((long long) xx[ii[j - 1]] - xx[ii[i]] + t * 2) * 2;
				}
				for (i = 0; i + 1 < n; i++)
					if (xx[ii[i + 1]] - xx[ii[i]] == t)
						ans += t - 1;
				printf("%lld\n", ans);
			}
		}
	}
	return 0;
}

Compilation message

cell.c: In function 'main':
cell.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
cell.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cell.c:74:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |    scanf("%d", &t);
      |    ^~~~~~~~~~~~~~~
cell.c:84:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   84 |    scanf("%d", &t);
      |    ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 374 ms 62924 KB Output is correct
2 Correct 369 ms 62932 KB Output is correct
3 Correct 378 ms 62928 KB Output is correct
4 Correct 368 ms 62920 KB Output is correct
5 Correct 375 ms 62920 KB Output is correct
6 Correct 366 ms 62936 KB Output is correct
7 Correct 375 ms 62924 KB Output is correct
8 Correct 376 ms 62996 KB Output is correct
9 Correct 380 ms 62920 KB Output is correct
10 Correct 397 ms 62924 KB Output is correct
11 Correct 382 ms 62924 KB Output is correct
12 Correct 379 ms 62932 KB Output is correct
13 Correct 373 ms 63036 KB Output is correct
14 Correct 371 ms 62928 KB Output is correct
15 Correct 418 ms 63052 KB Output is correct
16 Correct 376 ms 62924 KB Output is correct
17 Correct 385 ms 62932 KB Output is correct
18 Correct 386 ms 62920 KB Output is correct
19 Correct 376 ms 62920 KB Output is correct
20 Correct 393 ms 62916 KB Output is correct
21 Correct 375 ms 62940 KB Output is correct
22 Correct 409 ms 62864 KB Output is correct
23 Correct 362 ms 63052 KB Output is correct
24 Correct 355 ms 62920 KB Output is correct
25 Correct 399 ms 62932 KB Output is correct
26 Correct 386 ms 62924 KB Output is correct
27 Correct 422 ms 62932 KB Output is correct
28 Correct 366 ms 62920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 62924 KB Output is correct
2 Correct 369 ms 62932 KB Output is correct
3 Correct 378 ms 62928 KB Output is correct
4 Correct 368 ms 62920 KB Output is correct
5 Correct 375 ms 62920 KB Output is correct
6 Correct 366 ms 62936 KB Output is correct
7 Correct 375 ms 62924 KB Output is correct
8 Correct 376 ms 62996 KB Output is correct
9 Correct 380 ms 62920 KB Output is correct
10 Correct 397 ms 62924 KB Output is correct
11 Correct 382 ms 62924 KB Output is correct
12 Correct 379 ms 62932 KB Output is correct
13 Correct 373 ms 63036 KB Output is correct
14 Correct 371 ms 62928 KB Output is correct
15 Correct 418 ms 63052 KB Output is correct
16 Correct 376 ms 62924 KB Output is correct
17 Correct 385 ms 62932 KB Output is correct
18 Correct 386 ms 62920 KB Output is correct
19 Correct 376 ms 62920 KB Output is correct
20 Correct 393 ms 62916 KB Output is correct
21 Correct 375 ms 62940 KB Output is correct
22 Correct 409 ms 62864 KB Output is correct
23 Correct 362 ms 63052 KB Output is correct
24 Correct 355 ms 62920 KB Output is correct
25 Correct 399 ms 62932 KB Output is correct
26 Correct 386 ms 62924 KB Output is correct
27 Correct 422 ms 62932 KB Output is correct
28 Correct 366 ms 62920 KB Output is correct
29 Correct 358 ms 62932 KB Output is correct
30 Correct 359 ms 62920 KB Output is correct
31 Correct 389 ms 62924 KB Output is correct
32 Correct 382 ms 63696 KB Output is correct
33 Correct 364 ms 62924 KB Output is correct
34 Correct 383 ms 62924 KB Output is correct
35 Correct 361 ms 62840 KB Output is correct
36 Correct 371 ms 62920 KB Output is correct
37 Correct 366 ms 62924 KB Output is correct
38 Correct 389 ms 62928 KB Output is correct
39 Correct 365 ms 63000 KB Output is correct
40 Correct 378 ms 63700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1364 KB Output is correct
2 Correct 28 ms 1448 KB Output is correct
3 Correct 32 ms 1364 KB Output is correct
4 Correct 31 ms 1444 KB Output is correct
5 Correct 31 ms 1444 KB Output is correct
6 Correct 33 ms 1364 KB Output is correct
7 Correct 31 ms 1468 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 32 ms 1336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 1364 KB Output is correct
2 Correct 28 ms 1448 KB Output is correct
3 Correct 32 ms 1364 KB Output is correct
4 Correct 31 ms 1444 KB Output is correct
5 Correct 31 ms 1444 KB Output is correct
6 Correct 33 ms 1364 KB Output is correct
7 Correct 31 ms 1468 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 32 ms 1336 KB Output is correct
12 Runtime error 116 ms 128872 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 127344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 86 ms 127344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 374 ms 62924 KB Output is correct
2 Correct 369 ms 62932 KB Output is correct
3 Correct 378 ms 62928 KB Output is correct
4 Correct 368 ms 62920 KB Output is correct
5 Correct 375 ms 62920 KB Output is correct
6 Correct 366 ms 62936 KB Output is correct
7 Correct 375 ms 62924 KB Output is correct
8 Correct 376 ms 62996 KB Output is correct
9 Correct 380 ms 62920 KB Output is correct
10 Correct 397 ms 62924 KB Output is correct
11 Correct 382 ms 62924 KB Output is correct
12 Correct 379 ms 62932 KB Output is correct
13 Correct 373 ms 63036 KB Output is correct
14 Correct 371 ms 62928 KB Output is correct
15 Correct 418 ms 63052 KB Output is correct
16 Correct 376 ms 62924 KB Output is correct
17 Correct 385 ms 62932 KB Output is correct
18 Correct 386 ms 62920 KB Output is correct
19 Correct 376 ms 62920 KB Output is correct
20 Correct 393 ms 62916 KB Output is correct
21 Correct 375 ms 62940 KB Output is correct
22 Correct 409 ms 62864 KB Output is correct
23 Correct 362 ms 63052 KB Output is correct
24 Correct 355 ms 62920 KB Output is correct
25 Correct 399 ms 62932 KB Output is correct
26 Correct 386 ms 62924 KB Output is correct
27 Correct 422 ms 62932 KB Output is correct
28 Correct 366 ms 62920 KB Output is correct
29 Correct 358 ms 62932 KB Output is correct
30 Correct 359 ms 62920 KB Output is correct
31 Correct 389 ms 62924 KB Output is correct
32 Correct 382 ms 63696 KB Output is correct
33 Correct 364 ms 62924 KB Output is correct
34 Correct 383 ms 62924 KB Output is correct
35 Correct 361 ms 62840 KB Output is correct
36 Correct 371 ms 62920 KB Output is correct
37 Correct 366 ms 62924 KB Output is correct
38 Correct 389 ms 62928 KB Output is correct
39 Correct 365 ms 63000 KB Output is correct
40 Correct 378 ms 63700 KB Output is correct
41 Correct 29 ms 1364 KB Output is correct
42 Correct 28 ms 1448 KB Output is correct
43 Correct 32 ms 1364 KB Output is correct
44 Correct 31 ms 1444 KB Output is correct
45 Correct 31 ms 1444 KB Output is correct
46 Correct 33 ms 1364 KB Output is correct
47 Correct 31 ms 1468 KB Output is correct
48 Correct 0 ms 212 KB Output is correct
49 Correct 0 ms 212 KB Output is correct
50 Correct 0 ms 212 KB Output is correct
51 Correct 32 ms 1336 KB Output is correct
52 Runtime error 116 ms 128872 KB Execution killed with signal 11
53 Halted 0 ms 0 KB -