提出 #53008198


ソースコード 拡げる

Copy
#include <stdio.h>
int H, W;
char S[1024][1024];
char stop[1024][1024];
int gen = 0;
int visited[1024][1024];
int dfs(int y, int x) {
int cnt;
if (y < 0 || H <= y || x < 0 || W <= x) return 0;
if (visited[y][x] == gen) return 0;
if (S[y][x] == '#') return 0;
visited[y][x] = gen;
cnt = 1;
if (!stop[y][x]) {
cnt += dfs(y - 1, x);
cnt += dfs(y + 1, x);
cnt += dfs(y, x - 1);
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>

int H, W;
char S[1024][1024];

char stop[1024][1024];

int gen = 0;
int visited[1024][1024];

int dfs(int y, int x) {
	int cnt;
	if (y < 0 || H <= y || x < 0 || W <= x) return 0;
	if (visited[y][x] == gen) return 0;
	if (S[y][x] == '#') return 0;
	visited[y][x] = gen;
	cnt = 1;
	if (!stop[y][x]) {
		cnt += dfs(y - 1, x);
		cnt += dfs(y + 1, x);
		cnt += dfs(y, x - 1);
		cnt += dfs(y, x + 1);
	}
	return cnt;
}

int main(void) {
	int i, j;
	int ans = 0;
	if (scanf("%d%d", &H, &W) != 2) return 1;
	for (i = 0; i < H; i++) {
		if (scanf("%1023s", S[i]) != 1) return 1;
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			int this_stop = 0;
			this_stop = this_stop || (i > 0 && S[i - 1][j] == '#');
			this_stop = this_stop || (i + 1 < H && S[i + 1][j] == '#');
			this_stop = this_stop || (j > 0 && S[i][j - 1] == '#');
			this_stop = this_stop || (j + 1 < W && S[i][j + 1] == '#');
			stop[i][j] = this_stop;
		}
	}
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			if (S[i][j] != '#') {
				int candidate;
				gen++;
				candidate = dfs(i, j);
				if (candidate > ans) ans = candidate;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

提出情報

提出日時
問題 D - Grid and Magnet
ユーザ mikecat
言語 C (gcc 12.2.0)
得点 0
コード長 1230 Byte
結果 TLE
実行時間 2213 ms
メモリ 101252 KB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 0 / 425
結果
AC × 2
AC × 36
TLE × 16
セット名 テストケース
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
ケース名 結果 実行時間 メモリ
example_00.txt AC 1 ms 1664 KB
example_01.txt AC 1 ms 1728 KB
hand_00.txt AC 1 ms 1752 KB
hand_01.txt TLE 2213 ms 101252 KB
hand_02.txt AC 5 ms 3660 KB
hand_03.txt AC 9 ms 7612 KB
hand_04.txt AC 246 ms 7840 KB
hand_05.txt TLE 2211 ms 85516 KB
hand_06.txt TLE 2212 ms 85468 KB
hand_07.txt TLE 2213 ms 100876 KB
hand_08.txt TLE 2213 ms 100780 KB
hand_09.txt TLE 2210 ms 54120 KB
hand_10.txt TLE 2210 ms 54120 KB
hand_11.txt AC 1 ms 1636 KB
hand_12.txt AC 1 ms 1636 KB
hand_13.txt AC 1 ms 1728 KB
random_00.txt TLE 2210 ms 45192 KB
random_01.txt TLE 2209 ms 41796 KB
random_02.txt TLE 2209 ms 43712 KB
random_03.txt TLE 2208 ms 13376 KB
random_04.txt TLE 2208 ms 14472 KB
random_05.txt TLE 2208 ms 14540 KB
random_06.txt AC 199 ms 7576 KB
random_07.txt AC 203 ms 7572 KB
random_08.txt AC 204 ms 7708 KB
random_09.txt AC 20 ms 7712 KB
random_10.txt AC 20 ms 7712 KB
random_11.txt AC 20 ms 7576 KB
random_12.txt AC 7 ms 7628 KB
random_13.txt AC 7 ms 7732 KB
random_14.txt AC 7 ms 7556 KB
random_15.txt TLE 2213 ms 99560 KB
random_16.txt TLE 2212 ms 81924 KB
random_17.txt TLE 2209 ms 43312 KB
random_18.txt AC 4 ms 3612 KB
random_19.txt AC 5 ms 4092 KB
random_20.txt AC 7 ms 7696 KB
random_21.txt AC 9 ms 7584 KB
random_22.txt AC 9 ms 7544 KB
random_23.txt AC 9 ms 7600 KB
random_24.txt AC 13 ms 7568 KB
random_25.txt AC 14 ms 7608 KB
random_26.txt AC 13 ms 7580 KB
random_27.txt AC 13 ms 7712 KB
random_28.txt AC 13 ms 7564 KB
random_29.txt AC 13 ms 7720 KB
random_30.txt AC 31 ms 7752 KB
random_31.txt AC 88 ms 7748 KB
random_32.txt AC 75 ms 7652 KB
random_33.txt AC 76 ms 7748 KB
random_34.txt AC 245 ms 7828 KB
random_35.txt AC 396 ms 7896 KB


2024-05-02 (木)
07:27:06 +09:00