結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
63,772 KB
testcase_01 AC 48 ms
64,168 KB
testcase_02 AC 48 ms
63,512 KB
testcase_03 AC 48 ms
64,020 KB
testcase_04 AC 49 ms
64,824 KB
testcase_05 AC 47 ms
63,576 KB
testcase_06 AC 49 ms
64,232 KB
testcase_07 AC 46 ms
63,708 KB
testcase_08 AC 49 ms
64,556 KB
testcase_09 AC 47 ms
63,608 KB
testcase_10 AC 47 ms
63,616 KB
testcase_11 AC 48 ms
64,836 KB
testcase_12 AC 48 ms
63,208 KB
testcase_13 AC 50 ms
64,036 KB
testcase_14 AC 50 ms
63,632 KB
testcase_15 AC 46 ms
63,520 KB
testcase_16 AC 48 ms
64,084 KB
testcase_17 AC 48 ms
63,692 KB
testcase_18 AC 47 ms
63,676 KB
testcase_19 AC 49 ms
65,340 KB
testcase_20 AC 49 ms
64,800 KB
testcase_21 AC 50 ms
63,300 KB
testcase_22 AC 47 ms
63,684 KB
testcase_23 AC 50 ms
64,180 KB
testcase_24 AC 288 ms
89,932 KB
testcase_25 AC 268 ms
90,172 KB
testcase_26 AC 282 ms
90,432 KB
testcase_27 AC 269 ms
89,908 KB
testcase_28 AC 265 ms
89,928 KB
testcase_29 TLE -
testcase_30 AC 1,613 ms
184,664 KB
testcase_31 TLE -
testcase_32 AC 1,595 ms
185,136 KB
testcase_33 AC 1,620 ms
184,592 KB
testcase_34 AC 1,636 ms
185,236 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
    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()
0