結果
問題 |
No.697 池の数はいくつか
|
ユーザー |
|
提出日時 | 2018-06-24 13:26:50 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,038 bytes |
コンパイル時間 | 380 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 256,360 KB |
最終ジャッジ日時 | 2024-11-08 07:59:15 |
合計ジャッジ時間 | 13,251 ms |
ジャッジサーバーID (参考情報) |
judge1 / 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 write(str(ponds) + '\n') def bfs(h, w): g = deque([(h, w)]) Flag[h][w] = True apnd, popl = g.append, g.popleft while g: x, y = popl() 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: apnd((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()