結果

問題 No.697 池の数はいくつか
ユーザー GrayCoderGrayCoder
提出日時 2018-06-24 13:26:50
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,038 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 263,528 KB
最終ジャッジ日時 2024-04-25 20:14:04
合計ジャッジ時間 12,353 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 49 ms
63,956 KB
testcase_01 AC 48 ms
64,468 KB
testcase_02 AC 50 ms
63,992 KB
testcase_03 AC 48 ms
64,436 KB
testcase_04 AC 47 ms
64,304 KB
testcase_05 AC 48 ms
63,616 KB
testcase_06 AC 48 ms
63,988 KB
testcase_07 AC 49 ms
63,752 KB
testcase_08 AC 47 ms
64,188 KB
testcase_09 AC 48 ms
64,912 KB
testcase_10 AC 48 ms
64,800 KB
testcase_11 AC 47 ms
63,712 KB
testcase_12 AC 47 ms
63,596 KB
testcase_13 AC 49 ms
63,628 KB
testcase_14 AC 52 ms
63,956 KB
testcase_15 AC 51 ms
65,048 KB
testcase_16 AC 52 ms
64,452 KB
testcase_17 AC 47 ms
64,900 KB
testcase_18 AC 46 ms
63,640 KB
testcase_19 AC 48 ms
64,844 KB
testcase_20 AC 47 ms
63,548 KB
testcase_21 AC 47 ms
63,708 KB
testcase_22 AC 47 ms
64,248 KB
testcase_23 AC 47 ms
63,768 KB
testcase_24 AC 295 ms
90,036 KB
testcase_25 AC 287 ms
90,028 KB
testcase_26 AC 277 ms
90,052 KB
testcase_27 AC 270 ms
90,292 KB
testcase_28 AC 281 ms
90,180 KB
testcase_29 TLE -
testcase_30 AC 1,745 ms
185,376 KB
testcase_31 TLE -
testcase_32 AC 1,729 ms
184,908 KB
testcase_33 AC 1,749 ms
185,012 KB
testcase_34 AC 1,737 ms
184,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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()
0