結果
| 問題 | 
                            No.697 池の数はいくつか
                             | 
                    
| ユーザー | 
                             lllllll88938494
                         | 
                    
| 提出日時 | 2022-09-22 16:06:25 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 666 bytes | 
| コンパイル時間 | 365 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 979,864 KB | 
| 最終ジャッジ日時 | 2024-12-22 04:57:49 | 
| 合計ジャッジ時間 | 26,846 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 WA * 1 RE * 1 | 
| other | AC * 9 WA * 12 RE * 5 TLE * 1 MLE * 5 | 
ソースコード
from collections import deque
h,w=map(int,input().split())
grid=[list(map(int,input().split())) for i in range(h)]
f=[[0]*w for i in range(h)]
cnt = 1
l=[1,0,-1,0]
r=[0,1,0,-1]
for i in range(h):
    for j in range(w):
        if grid[i][j] == 1 and f[i][j] ==0:
            d=deque()
            d.append((i,j))
            while d:
                x,y=d.popleft()
                f[x][y] = cnt
                for i in range(4):
                    if 0 <= x + l[i] < h and 0 <= y + r[i] < w:
                        if grid[x+l[i]][y+r[i]] == 1 and f[x+l[i]][y+r[i]] == 0:
                            d.append((x+l[i],y+r[i]))
            cnt+=1
print(cnt-1) 
            
            
            
        
            
lllllll88938494