답안 #817135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817135 2023-08-09T09:46:23 Z rainboy Cell Automaton (JOI23_cell) C
0 / 100
371 ms 127388 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], tt[N];

int compare_x(int i, int j) { return xx[i] - xx[j]; }
int compare_t(int i, int j) { return tt[i] - tt[j]; }

int (*compare)(int, int);

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, i_, x, y, t, subtask;
	long long a, b;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i], &yy[i]);
	subtask = 3;
	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;
		compare = compare_x, sort(ii, 0, n);
		for (i = 0; i + 1 < n; i++) {
			tt[i] = xx[ii[i + 1]] - xx[ii[i]];
			ii[i] = i;
		}
		compare = compare_t, sort(ii, 0, n - 1);
		i = 0, a = n * 4, b = 0;
		while (q--) {
			long long ans;

			scanf("%d", &t);
			if (t == 0)
				printf("%d\n", n);
			else {
				while (i < n - 1 && tt[i_ = ii[i]] < t) {
					a -= 4, b += tt[i_] * 2;
					i++;
				}
				ans = 0;
				while (i < n - 1 && tt[i_ = ii[i]] == t) {
					a -= 4, b += tt[i_] * 2;
					i++;
					ans += t - 1;
				}
				ans += a * t + b;
				printf("%lld\n", ans);
			}
		}
	}
	return 0;
}

Compilation message

cell.c: In function 'main':
cell.c:46:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
cell.c:48:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |   scanf("%d%d", &xx[i], &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cell.c:78:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |    scanf("%d", &t);
      |    ^~~~~~~~~~~~~~~
cell.c:94:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |    scanf("%d", &t);
      |    ^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 371 ms 62928 KB Output is correct
2 Correct 353 ms 62824 KB Output is correct
3 Correct 341 ms 62924 KB Output is correct
4 Correct 346 ms 62924 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 371 ms 62928 KB Output is correct
2 Correct 353 ms 62824 KB Output is correct
3 Correct 341 ms 62924 KB Output is correct
4 Correct 346 ms 62924 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 1788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 1788 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 127388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 81 ms 127388 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 371 ms 62928 KB Output is correct
2 Correct 353 ms 62824 KB Output is correct
3 Correct 341 ms 62924 KB Output is correct
4 Correct 346 ms 62924 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 Halted 0 ms 0 KB -