結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2019-09-16 19:43:41 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 691 bytes |
コンパイル時間 | 527 ms |
コンパイル使用メモリ | 82,236 KB |
実行使用メモリ | 244,672 KB |
最終ジャッジ日時 | 2024-11-25 15:23:08 |
合計ジャッジ時間 | 12,495 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 13 |
ソースコード
import sys input = sys.stdin.readline from collections import deque H,W = map(int,input().split()) A = [list(map(int,input().split())) for y in range(H)] ans = 0 dxy = [(-1,0), (0,-1), (0,1), (1,0)] for y in range(H) : for x in range(W) : if A[y][x] != 1 : continue ans += 1 A[y][x] = 0 q = deque([(y, x)]) while q : y, x = q.popleft() for dy,dx in dxy : ny,nx = y+dy, x+dx if ny<0 or ny>=H or nx<0 or nx>=W : continue if A[ny][nx] != 1 : continue q.append((ny, nx)) A[ny][nx] = 0 print(ans)