結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
12,948 KB
testcase_01 AC 22 ms
8,444 KB
testcase_02 AC 22 ms
8,440 KB
testcase_03 AC 21 ms
8,504 KB
testcase_04 AC 22 ms
8,468 KB
testcase_05 AC 21 ms
8,616 KB
testcase_06 AC 22 ms
8,564 KB
testcase_07 AC 23 ms
8,508 KB
testcase_08 AC 22 ms
8,572 KB
testcase_09 AC 22 ms
8,628 KB
testcase_10 AC 20 ms
8,460 KB
testcase_11 AC 22 ms
8,616 KB
testcase_12 AC 22 ms
8,640 KB
testcase_13 AC 22 ms
8,564 KB
testcase_14 AC 22 ms
8,620 KB
testcase_15 AC 21 ms
8,636 KB
testcase_16 AC 20 ms
8,616 KB
testcase_17 AC 22 ms
8,464 KB
testcase_18 AC 20 ms
8,636 KB
testcase_19 AC 21 ms
8,444 KB
testcase_20 AC 22 ms
8,628 KB
testcase_21 AC 20 ms
8,500 KB
testcase_22 AC 20 ms
8,584 KB
testcase_23 AC 20 ms
8,584 KB
testcase_24 AC 752 ms
17,260 KB
testcase_25 AC 771 ms
17,440 KB
testcase_26 AC 773 ms
17,320 KB
testcase_27 AC 792 ms
17,376 KB
testcase_28 AC 779 ms
17,360 KB
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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