結果

問題 No.697 池の数はいくつか
ユーザー roarisroaris
提出日時 2019-08-12 11:34:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 702 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 10,772 KB
実行使用メモリ 89,896 KB
最終ジャッジ日時 2023-08-16 23:12:08
合計ジャッジ時間 13,576 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,416 KB
testcase_01 AC 19 ms
8,592 KB
testcase_02 AC 19 ms
8,444 KB
testcase_03 AC 19 ms
8,492 KB
testcase_04 AC 19 ms
8,632 KB
testcase_05 AC 19 ms
8,564 KB
testcase_06 AC 19 ms
8,632 KB
testcase_07 AC 19 ms
8,604 KB
testcase_08 AC 20 ms
8,516 KB
testcase_09 AC 19 ms
8,572 KB
testcase_10 AC 19 ms
8,456 KB
testcase_11 AC 19 ms
8,496 KB
testcase_12 AC 19 ms
8,492 KB
testcase_13 AC 19 ms
8,560 KB
testcase_14 AC 19 ms
8,632 KB
testcase_15 AC 19 ms
8,496 KB
testcase_16 AC 19 ms
8,520 KB
testcase_17 AC 19 ms
8,588 KB
testcase_18 AC 19 ms
8,520 KB
testcase_19 AC 19 ms
8,560 KB
testcase_20 AC 19 ms
8,520 KB
testcase_21 AC 19 ms
8,568 KB
testcase_22 AC 19 ms
8,564 KB
testcase_23 AC 19 ms
8,412 KB
testcase_24 AC 731 ms
17,344 KB
testcase_25 AC 740 ms
17,436 KB
testcase_26 AC 734 ms
17,316 KB
testcase_27 AC 732 ms
17,432 KB
testcase_28 AC 742 ms
17,336 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline

def bfs(sx, sy):
    S[sx][sy] = 0
    queue = deque([])
    queue.append((sx, sy))
    
    while len(queue) > 0:
        cx, cy = queue.popleft()
        
        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            nx, ny = cx + dx, cy + dy
            if 0 <= nx < H and 0 <= ny < W:
                if S[nx][ny] == 1:
                    S[nx][ny] = 0
                    queue.append((nx, ny))
    
H, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(H)]
ans = 0

for i in range(H):
    for j in range(W):
        if S[i][j] == 1:
            bfs(i, j)
            ans += 1

print(ans)
0