Submission #69932987


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
int H, W;
char** S;
struct yx_s {
int y, x;
};
struct yx_s listbuf[2][312345];
int main(void) {
char buf[128];
int i, j;
int cnt = 0, next_cnt = 0;
struct yx_s* list = listbuf[0], *next_list = listbuf[1], *temp;
int ans = 0;
if (fgets(buf, sizeof(buf), stdin) == NULL || sscanf(buf, "%d%d", &H, &W) != 2) return 1;
S = malloc(sizeof(*S) * H);
if (S == NULL) return 2;
S[0] = malloc(sizeof(**S) * (W + 8) * H);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>

int H, W;
char** S;

struct yx_s {
	int y, x;
};
struct yx_s listbuf[2][312345];

int main(void) {
	char buf[128];
	int i, j;
	int cnt = 0, next_cnt = 0;
	struct yx_s* list = listbuf[0], *next_list = listbuf[1], *temp;
	int ans = 0;
	if (fgets(buf, sizeof(buf), stdin) == NULL || sscanf(buf, "%d%d", &H, &W) != 2) return 1;
	S = malloc(sizeof(*S) * H);
	if (S == NULL) return 2;
	S[0] = malloc(sizeof(**S) * (W + 8) * H);
	if (S[0] == NULL) return 2;
	for (i = 0; i < H; i++) {
		S[i] = S[0] + (size_t)(W + 8) * i;
		if (fgets(S[i], W + 8, stdin) == NULL) return 1;
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (S[i][j] == '#') {
				list[cnt++] = (struct yx_s){ i, j };
			}
		}
	}
	while (cnt > 0) {
		/* 前のイテレーションで増えた黒マスの周辺のみをチェックする */
		for (i = 0; i < cnt; i++) {
			for (j = 0; j < 4; j++) {
				int y = list[i].y + (j < 2) * ((j & 1) * 2 - 1);
				int x = list[i].x + (j >= 2) * ((j & 1) * 2 - 1);
				if (0 <= y && y < H && 0 <= x && x < W && S[y][x] != '#') {
					int k, rcnt = 0;
					for (k = 0; k < 4; k++) {
						/* sample y/x */
						int sy = y + (k < 2) * ((k & 1) * 2 - 1);
						int sx = x + (k >= 2) * ((k & 1) * 2 - 1);
						rcnt += 0 <= sy && sy < H && 0 <= sx && sx < W && S[sy][sx] == '#';
					}
					if (rcnt == 1) {
						next_list[next_cnt++] = (struct yx_s){ y, x };
					}
				}
			}
		}
		for (i = 0; i < next_cnt; i++) {
			S[next_list[i].y][next_list[i].x] = '#';
		}
		cnt = next_cnt;
		temp = list;
		list = next_list;
		next_list = temp;
		next_cnt = 0;
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			ans += S[i][j] == '#';
		}
	}
	printf("%d\n", ans);
	free(S[0]);
	free(S);
	return 0;
}

Submission Info

Submission Time
Task D - Ulam-Warburton Automaton
User mikecat
Language C (gcc 12.2.0)
Score 425
Code Size 1828 Byte
Status AC
Exec Time 12 ms
Memory 3352 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 40
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_test_00.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt, 01_test_27.txt, 01_test_28.txt, 01_test_29.txt, 01_test_30.txt, 01_test_31.txt, 01_test_32.txt, 01_test_33.txt, 01_test_34.txt, 01_test_35.txt, 01_test_36.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 1708 KiB
00_sample_01.txt AC 1 ms 1636 KiB
00_sample_02.txt AC 1 ms 1600 KiB
01_test_00.txt AC 10 ms 2880 KiB
01_test_01.txt AC 4 ms 2244 KiB
01_test_02.txt AC 5 ms 2432 KiB
01_test_03.txt AC 8 ms 2580 KiB
01_test_04.txt AC 10 ms 2576 KiB
01_test_05.txt AC 11 ms 3236 KiB
01_test_06.txt AC 11 ms 3300 KiB
01_test_07.txt AC 10 ms 3212 KiB
01_test_08.txt AC 12 ms 2824 KiB
01_test_09.txt AC 12 ms 2764 KiB
01_test_10.txt AC 7 ms 1656 KiB
01_test_11.txt AC 8 ms 1752 KiB
01_test_12.txt AC 9 ms 1780 KiB
01_test_13.txt AC 9 ms 2088 KiB
01_test_14.txt AC 10 ms 2040 KiB
01_test_15.txt AC 9 ms 2040 KiB
01_test_16.txt AC 9 ms 1976 KiB
01_test_17.txt AC 10 ms 2260 KiB
01_test_18.txt AC 11 ms 2308 KiB
01_test_19.txt AC 12 ms 2576 KiB
01_test_20.txt AC 7 ms 1768 KiB
01_test_21.txt AC 7 ms 1712 KiB
01_test_22.txt AC 7 ms 1728 KiB
01_test_23.txt AC 8 ms 1744 KiB
01_test_24.txt AC 8 ms 1716 KiB
01_test_25.txt AC 8 ms 1792 KiB
01_test_26.txt AC 8 ms 1732 KiB
01_test_27.txt AC 9 ms 2040 KiB
01_test_28.txt AC 9 ms 2276 KiB
01_test_29.txt AC 11 ms 3352 KiB
01_test_30.txt AC 10 ms 2576 KiB
01_test_31.txt AC 9 ms 2296 KiB
01_test_32.txt AC 10 ms 2796 KiB
01_test_33.txt AC 10 ms 2488 KiB
01_test_34.txt AC 10 ms 2376 KiB
01_test_35.txt AC 10 ms 2372 KiB
01_test_36.txt AC 7 ms 1728 KiB


2025-10-07 (Tue)
04:11:33 +09:00