結果

問題 No.697 池の数はいくつか
ユーザー kawacchukawacchu
提出日時 2019-09-16 19:57:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 801 bytes
コンパイル時間 198 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 94,752 KB
最終ジャッジ日時 2024-05-04 06:44:45
合計ジャッジ時間 12,929 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import deque
def main() :
    H,W = map(int,input().split())
    A = [list(map(int,input().split())) for y in range(H)]
    ans = 0
    dxy = [(-1,0), (0,-1), (0,1), (1,0)]

    for i in range(H) :
        for j in range(W) :
            if A[i][j] != 1 :
                continue
            ans += 1
            A[i][j] = 0
            q = deque([(i, j)])
            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)
main()
0