結果

問題 No.697 池の数はいくつか
ユーザー DrDrpilot
提出日時 2022-01-21 16:02:34
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 596 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 98,432 KB
最終ジャッジ日時 2024-11-25 17:17:45
合計ジャッジ時間 49,406 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 TLE * 6
権限があれば一括ダウンロードができます

ソースコード

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