提出 #74308652
ソースコード 拡げる
H, W = map(int, input().split())
S = []
OK = [[False for _ in range(W)] for _ in range(H)]
for _ in range(H):
S.append(list(input()))
ct = 0
for i in range(H):
for j in range(W):
if not OK[i][j]:
OK[i][j] = True
if S[i][j] == '.':
ct += 1
ct_ct = 0
dfs = [(i, j)]
while len(dfs) > 0:
h, w = dfs.pop()
if h == 0 or h == H - 1 or w == 0 or w == W - 1:
ct_ct += 1
if w > 0 and S[h][w - 1] == '.' and not OK[h][w - 1]:
OK[h][w - 1] = True
dfs.append((h, w - 1))
if h > 0 and S[h - 1][w] == '.' and not OK[h - 1][w]:
OK[h - 1][w] = True
dfs.append((h - 1, w))
if h < H - 1 and S[h + 1][w] == '.' and not OK[h + 1][w]:
OK[h + 1][w] = True
dfs.append((h + 1, w))
if w < W - 1 and S[h][w + 1] == '.' and not OK[h][w + 1]:
OK[h][w + 1] = True
dfs.append((h, w + 1))
else:
if ct_ct > 0:
ct -= 1
print(ct)
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Puddles |
| ユーザ | fnare |
| 言語 | Python (PyPy 3.11-v7.3.20) |
| 得点 | 300 |
| コード長 | 1331 Byte |
| 結果 | AC |
| 実行時間 | 362 ms |
| メモリ | 198340 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | sample_01.txt, sample_02.txt |
| All | min.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, sample_01.txt, sample_02.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| min.txt | AC | 51 ms | 79804 KiB |
| random_01.txt | AC | 169 ms | 157076 KiB |
| random_02.txt | AC | 113 ms | 123252 KiB |
| random_03.txt | AC | 167 ms | 157132 KiB |
| random_04.txt | AC | 130 ms | 123932 KiB |
| random_05.txt | AC | 230 ms | 157684 KiB |
| random_06.txt | AC | 88 ms | 107296 KiB |
| random_07.txt | AC | 230 ms | 157696 KiB |
| random_08.txt | AC | 100 ms | 110596 KiB |
| random_09.txt | AC | 359 ms | 160188 KiB |
| random_10.txt | AC | 314 ms | 146828 KiB |
| random_11.txt | AC | 362 ms | 160044 KiB |
| random_12.txt | AC | 74 ms | 96236 KiB |
| random_13.txt | AC | 351 ms | 176908 KiB |
| random_14.txt | AC | 150 ms | 113100 KiB |
| random_15.txt | AC | 345 ms | 175640 KiB |
| random_16.txt | AC | 219 ms | 130244 KiB |
| random_17.txt | AC | 103 ms | 124432 KiB |
| random_18.txt | AC | 267 ms | 198340 KiB |
| random_19.txt | AC | 138 ms | 156320 KiB |
| random_20.txt | AC | 142 ms | 156360 KiB |
| random_21.txt | AC | 141 ms | 156160 KiB |
| sample_01.txt | AC | 55 ms | 79924 KiB |
| sample_02.txt | AC | 53 ms | 79780 KiB |