結果

問題 No.697 池の数はいくつか
ユーザー kawacchukawacchu
提出日時 2019-09-16 19:31:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 654 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 19,584 KB
最終ジャッジ日時 2024-05-04 06:43:38
合計ジャッジ時間 17,824 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 28 ms
10,624 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 26 ms
10,752 KB
testcase_04 WA -
testcase_05 AC 27 ms
10,752 KB
testcase_06 AC 28 ms
10,880 KB
testcase_07 AC 27 ms
10,752 KB
testcase_08 AC 27 ms
10,496 KB
testcase_09 AC 26 ms
10,752 KB
testcase_10 WA -
testcase_11 AC 28 ms
10,624 KB
testcase_12 AC 27 ms
10,624 KB
testcase_13 WA -
testcase_14 AC 29 ms
10,752 KB
testcase_15 AC 29 ms
10,496 KB
testcase_16 AC 29 ms
10,624 KB
testcase_17 AC 28 ms
10,624 KB
testcase_18 AC 28 ms
10,752 KB
testcase_19 AC 28 ms
10,752 KB
testcase_20 AC 27 ms
10,624 KB
testcase_21 AC 27 ms
10,752 KB
testcase_22 AC 27 ms
10,752 KB
testcase_23 AC 27 ms
10,752 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 TLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
H,W = map(int,input().split())
A = [list(map(int,input().split())) for y in range(H)]
ans = 0
dxy = [(-1,0), (1,0), (0,-1), (0,1)]
for y in range(H) :
    for x in range(W) :
        if A[y][x] != 1 :
            continue
        ans += 1
        A[y][x] = 0
        q = deque([(y, x)])
        while q :
            y, x = q.popleft()
            for dy,dx in dxy :
                ny,nx = y+dy, x+dx
                if ny<0 or ny>=H or nx<0 or nx>=W :
                    continue
                if A[ny][nx] != 1 :
                    continue
                q.append((ny, nx))
                A[ny][nx] = 0
print(ans)
0