結果

問題 No.697 池の数はいくつか
ユーザー rlangevinrlangevin
提出日時 2023-01-26 20:36:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,196 ms / 6,000 ms
コード長 857 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 284,388 KB
最終ジャッジ日時 2023-09-09 19:25:06
合計ジャッジ時間 17,530 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
71,224 KB
testcase_01 AC 89 ms
71,536 KB
testcase_02 AC 92 ms
71,072 KB
testcase_03 AC 91 ms
71,524 KB
testcase_04 AC 88 ms
71,280 KB
testcase_05 AC 88 ms
71,464 KB
testcase_06 AC 89 ms
71,528 KB
testcase_07 AC 90 ms
71,164 KB
testcase_08 AC 92 ms
71,052 KB
testcase_09 AC 91 ms
71,048 KB
testcase_10 AC 92 ms
71,072 KB
testcase_11 AC 91 ms
71,268 KB
testcase_12 AC 92 ms
71,532 KB
testcase_13 AC 91 ms
70,924 KB
testcase_14 AC 91 ms
71,432 KB
testcase_15 AC 90 ms
71,048 KB
testcase_16 AC 90 ms
71,052 KB
testcase_17 AC 90 ms
71,428 KB
testcase_18 AC 91 ms
71,268 KB
testcase_19 AC 88 ms
71,508 KB
testcase_20 AC 88 ms
71,432 KB
testcase_21 AC 89 ms
71,268 KB
testcase_22 AC 87 ms
71,420 KB
testcase_23 AC 90 ms
71,456 KB
testcase_24 AC 315 ms
96,988 KB
testcase_25 AC 316 ms
97,048 KB
testcase_26 AC 307 ms
97,232 KB
testcase_27 AC 307 ms
97,052 KB
testcase_28 AC 312 ms
97,064 KB
testcase_29 AC 2,196 ms
284,388 KB
testcase_30 AC 1,676 ms
267,196 KB
testcase_31 AC 2,124 ms
282,644 KB
testcase_32 AC 1,648 ms
267,644 KB
testcase_33 AC 1,667 ms
266,824 KB
testcase_34 AC 1,685 ms
267,552 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

H, W = map(int, input().split())
G = []
for i in range(H):
    G.append(list(map(int, input().split())))
    
seen = [0] * (H * W)
ans = 0
Q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for i in range(H):
    for j in range(W):
        if not G[i][j]:
            continue
        if seen[i*W+j]:
            continue
        seen[i*W+j] = 1
        ans += 1
        Q.append(i*W+j)
        while Q:
            px, py = divmod(Q.popleft(), W)
            for k in range(4):
                x = px + dx[k]
                y = py + dy[k]
                if x < 0 or x > H - 1 or y < 0 or y > W - 1:
                    continue
                if seen[x*W+y]:
                    continue
                if not G[x][y]:
                    continue
                seen[x*W+y] = 1
                Q.append(x * W + y)
print(ans)
0