結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2020-02-07 16:04:57 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 896 bytes |
コンパイル時間 | 201 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 174,848 KB |
最終ジャッジ日時 | 2024-11-25 15:54:23 |
合計ジャッジ時間 | 39,886 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 TLE * 2 |
ソースコード
from collections import deque import sys input = sys.stdin.readline def main(): H, W = map(int, input().split()) A = [[c != "0" for c in input().split()] for _ in range(H)] dire = [(-1,0),(0,1),(1,0),(0,-1)] ans = 0 for h in range(H): for w in range(W): if not A[h][w]: continue ans += 1 frontier = deque() frontier.append((h, w)) while frontier: y, x = frontier.popleft() for d, r in dire: suc_y = y+d suc_x = x+r if suc_y >= H or suc_x >= W or \ suc_y < 0 or suc_x < 0 or \ not A[suc_y][suc_x]: continue frontier.append((suc_y, suc_x)) A[suc_y][suc_x] = False print(ans) main()