結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             AEn
                         | 
                    
| 提出日時 | 2022-05-26 18:06:41 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 4,133 ms / 6,000 ms | 
| コード長 | 796 bytes | 
| コンパイル時間 | 398 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 287,552 KB | 
| 最終ジャッジ日時 | 2024-11-08 09:03:03 | 
| 合計ジャッジ時間 | 22,494 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 32 | 
ソースコード
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)
            
            
            
        
            
AEn