結果

問題 No.697 池の数はいくつか
ユーザー convexineqconvexineq
提出日時 2021-05-11 01:53:47
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 479 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,172 KB
実行使用メモリ 410,148 KB
最終ジャッジ日時 2024-05-04 07:24:52
合計ジャッジ時間 11,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
52,496 KB
testcase_01 AC 37 ms
53,324 KB
testcase_02 AC 32 ms
53,000 KB
testcase_03 AC 36 ms
52,208 KB
testcase_04 AC 36 ms
51,812 KB
testcase_05 AC 35 ms
52,352 KB
testcase_06 AC 38 ms
53,624 KB
testcase_07 AC 37 ms
52,144 KB
testcase_08 AC 36 ms
52,160 KB
testcase_09 AC 34 ms
52,716 KB
testcase_10 AC 33 ms
53,032 KB
testcase_11 AC 33 ms
52,868 KB
testcase_12 AC 33 ms
52,416 KB
testcase_13 AC 34 ms
52,312 KB
testcase_14 AC 34 ms
53,760 KB
testcase_15 AC 33 ms
52,952 KB
testcase_16 AC 34 ms
53,352 KB
testcase_17 AC 35 ms
53,124 KB
testcase_18 AC 35 ms
53,340 KB
testcase_19 AC 33 ms
53,756 KB
testcase_20 AC 32 ms
52,212 KB
testcase_21 AC 33 ms
53,372 KB
testcase_22 AC 34 ms
52,964 KB
testcase_23 AC 34 ms
53,004 KB
testcase_24 AC 198 ms
85,620 KB
testcase_25 AC 186 ms
85,620 KB
testcase_26 AC 185 ms
85,644 KB
testcase_27 AC 185 ms
85,544 KB
testcase_28 AC 192 ms
85,476 KB
testcase_29 MLE -
testcase_30 AC 1,002 ms
166,044 KB
testcase_31 MLE -
testcase_32 AC 968 ms
166,000 KB
testcase_33 AC 949 ms
165,716 KB
testcase_34 AC 947 ms
165,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(h)]

def dfs(i,j):
    a[i][j] = 0
    q = [(i,j)]
    while q:
        i,j = q.pop()
        for ni,nj in [(i+1,j),(i-1,j),(i,j+1),(i,j-1)]:
            if 0 <= ni < h and 0 <= nj < w and a[ni][nj] == 1:
                a[ni][nj] = 0
                q.append((ni,nj))

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] == 1:
            ans += 1
            dfs(i,j)
print(ans)
0