結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-06-24 09:30:26 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 998 bytes |
コンパイル時間 | 263 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 268,652 KB |
最終ジャッジ日時 | 2024-11-08 07:56:48 |
合計ジャッジ時間 | 12,876 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 TLE * 1 -- * 5 |
ソースコード
import re from collections import deque from sys import stdin, stdout input = lambda: stdin.readline().rstrip() write = stdout.write def main(): regex = re.compile(r'1+') ponds = 0 for i in range(H): r = 0 while 1: obj = regex.search(A[i], pos=r) if obj is None: break l, r = obj.start(), obj.end() if Flag[i][l] is None: bfs(i, l) ponds += 1 print(ponds) def bfs(h, w): g = deque([(h, w)]) Flag[h][w] = True while g: x, y = g.popleft() for i, j in {(1, 0), (-1, 0), (0, 1), (0, -1)}: xi, yj = x + i, y + j if 0 <= xi < H and 0 <= yj < W: if A[xi][yj] == '1' and Flag[xi][yj] is None: g.append((xi, yj)) Flag[xi][yj] = True return H, W = map(int, input().split()) A = stdin.read().replace(' ', '').splitlines() Flag = [[None] * W for _ in [0] * H] main()