結果

問題 No.697 池の数はいくつか
ユーザー AEnAEn
提出日時 2022-05-26 18:06:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 3,745 ms / 6,000 ms
コード長 796 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 82,556 KB
実行使用メモリ 287,436 KB
最終ジャッジ日時 2024-04-25 21:09:03
合計ジャッジ時間 20,118 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,148 KB
testcase_01 AC 39 ms
55,108 KB
testcase_02 AC 40 ms
54,748 KB
testcase_03 AC 40 ms
54,676 KB
testcase_04 AC 40 ms
55,768 KB
testcase_05 AC 40 ms
54,504 KB
testcase_06 AC 40 ms
55,296 KB
testcase_07 AC 40 ms
55,116 KB
testcase_08 AC 40 ms
54,044 KB
testcase_09 AC 39 ms
55,408 KB
testcase_10 AC 40 ms
54,688 KB
testcase_11 AC 39 ms
54,396 KB
testcase_12 AC 38 ms
55,024 KB
testcase_13 AC 40 ms
55,768 KB
testcase_14 AC 40 ms
54,072 KB
testcase_15 AC 40 ms
54,720 KB
testcase_16 AC 40 ms
54,096 KB
testcase_17 AC 40 ms
53,860 KB
testcase_18 AC 39 ms
54,196 KB
testcase_19 AC 40 ms
55,456 KB
testcase_20 AC 40 ms
55,444 KB
testcase_21 AC 42 ms
54,824 KB
testcase_22 AC 41 ms
53,928 KB
testcase_23 AC 39 ms
54,208 KB
testcase_24 AC 304 ms
96,920 KB
testcase_25 AC 288 ms
97,008 KB
testcase_26 AC 302 ms
96,912 KB
testcase_27 AC 296 ms
96,796 KB
testcase_28 AC 309 ms
97,084 KB
testcase_29 AC 3,745 ms
287,436 KB
testcase_30 AC 1,935 ms
265,412 KB
testcase_31 AC 3,730 ms
282,100 KB
testcase_32 AC 1,946 ms
265,744 KB
testcase_33 AC 1,960 ms
265,588 KB
testcase_34 AC 1,944 ms
265,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H, W = map(int, input().split())
m = []
for i in range(H):
    m.append(list(map(int, input().split())))

xx = [1, 0, -1, 0]
yy = [0, 1, 0, -1]

q = deque()
cnt = 0
seen = [[False]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if seen[i][j] == False and m[i][j] == 1:
            seen[i][j] = True
            q.append((i, j))
            cnt += 1
            while q:
                x, y = q.popleft()
                for px, py in zip(xx, yy):
                    cx = x+px
                    cy = y+py
                    if 0<=cx<H and 0<=cy<W and m[cx][cy] == 1 and seen[cx][cy] == False:
                        q.append((cx, cy))
                        seen[cx][cy] = True
        else:
            seen[i][j] = True
print(cnt)


0