結果

問題 No.697 池の数はいくつか
ユーザー neko_the_shadowneko_the_shadow
提出日時 2018-06-09 22:18:16
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 603 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 849,752 KB
最終ジャッジ日時 2024-05-04 05:35:44
合計ジャッジ時間 7,817 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
52,452 KB
testcase_01 AC 33 ms
53,700 KB
testcase_02 AC 33 ms
54,368 KB
testcase_03 AC 33 ms
53,080 KB
testcase_04 AC 34 ms
53,548 KB
testcase_05 AC 35 ms
52,984 KB
testcase_06 AC 35 ms
53,548 KB
testcase_07 AC 36 ms
52,896 KB
testcase_08 AC 35 ms
53,136 KB
testcase_09 AC 34 ms
53,476 KB
testcase_10 AC 35 ms
53,420 KB
testcase_11 AC 37 ms
52,408 KB
testcase_12 AC 35 ms
53,984 KB
testcase_13 AC 33 ms
52,852 KB
testcase_14 AC 33 ms
52,616 KB
testcase_15 AC 33 ms
53,376 KB
testcase_16 AC 34 ms
52,708 KB
testcase_17 AC 32 ms
52,864 KB
testcase_18 AC 32 ms
53,464 KB
testcase_19 AC 32 ms
52,552 KB
testcase_20 AC 32 ms
54,120 KB
testcase_21 AC 33 ms
53,932 KB
testcase_22 AC 34 ms
52,528 KB
testcase_23 AC 34 ms
54,308 KB
testcase_24 AC 270 ms
86,076 KB
testcase_25 AC 267 ms
86,068 KB
testcase_26 AC 255 ms
85,812 KB
testcase_27 AC 265 ms
85,576 KB
testcase_28 AC 262 ms
85,508 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools

if __name__ == '__main__':
    h, w = map(int, input().split())
    matrix = [list(map(int, input().split())) for _ in range(h)]
    
    diffs = ((1, 0), (-1, 0), (0, 1), (0, -1))
    counter = 0
    for x, y in itertools.product(range(h), range(w)):
        if matrix[x][y] == 0: continue
        
        counter += 1
        stack = [(x, y)]
        while stack:
            i, j = stack.pop()
            if 0 <= i < h and 0 <= j < w and matrix[i][j] == 1:
                matrix[i][j] = 0
                stack.extend((i + di, j + dj) for di, dj in diffs)
    
    print(counter)
0