結果

問題 No.697 池の数はいくつか
ユーザー DrDrpilotDrDrpilot
提出日時 2022-01-21 16:03:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,304 ms / 6,000 ms
コード長 596 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 82,668 KB
実行使用メモリ 254,856 KB
最終ジャッジ日時 2024-04-25 21:07:22
合計ジャッジ時間 13,410 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,528 KB
testcase_01 AC 37 ms
54,380 KB
testcase_02 AC 36 ms
53,808 KB
testcase_03 AC 38 ms
54,644 KB
testcase_04 AC 38 ms
54,856 KB
testcase_05 AC 39 ms
53,904 KB
testcase_06 AC 36 ms
54,308 KB
testcase_07 AC 39 ms
54,200 KB
testcase_08 AC 36 ms
54,812 KB
testcase_09 AC 40 ms
55,400 KB
testcase_10 AC 42 ms
54,680 KB
testcase_11 AC 37 ms
54,644 KB
testcase_12 AC 37 ms
54,024 KB
testcase_13 AC 38 ms
54,276 KB
testcase_14 AC 38 ms
54,420 KB
testcase_15 AC 39 ms
54,496 KB
testcase_16 AC 39 ms
54,240 KB
testcase_17 AC 40 ms
54,856 KB
testcase_18 AC 38 ms
55,720 KB
testcase_19 AC 39 ms
53,492 KB
testcase_20 AC 39 ms
54,056 KB
testcase_21 AC 39 ms
55,444 KB
testcase_22 AC 40 ms
54,136 KB
testcase_23 AC 39 ms
54,960 KB
testcase_24 AC 224 ms
86,260 KB
testcase_25 AC 219 ms
86,444 KB
testcase_26 AC 216 ms
86,240 KB
testcase_27 AC 227 ms
86,252 KB
testcase_28 AC 238 ms
86,324 KB
testcase_29 AC 2,098 ms
254,848 KB
testcase_30 AC 1,161 ms
166,724 KB
testcase_31 AC 2,304 ms
254,856 KB
testcase_32 AC 1,110 ms
166,524 KB
testcase_33 AC 1,317 ms
166,408 KB
testcase_34 AC 1,112 ms
166,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
h,w=map(int,input().split())
g=[list(map(int,input().split())) for _ in range(h)]
def bfs(i,j):
    g[i][j]=0
    q=deque()
    q.append((i,j))
    while q:
        i,j=q.popleft()
        dy=[0,1,0,-1]
        dx=[1,0,-1,0]
        for k in range(4):
            y=i+dy[k]
            x=j+dx[k]
            if not(0<=y<h and 0<=x<w):
                continue
            if g[y][x]==1:
                g[y][x]=0
                q.append((y,x))
ans=0
for i in range(h):
    for j in range(w):
        if g[i][j]==1:
            ans+=1
            bfs(i,j)
print(ans)
0