結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
![]() |
提出日時 | 2019-09-16 19:34:25 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 724 bytes |
コンパイル時間 | 215 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 98,432 KB |
最終ジャッジ日時 | 2024-11-25 15:22:02 |
合計ジャッジ時間 | 56,199 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 8 WA * 18 TLE * 6 |
ソースコード
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,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1), (1,0), (1,1)] 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)