結果

問題 No.697 池の数はいくつか
ユーザー kawacchukawacchu
提出日時 2019-09-16 19:43:41
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 691 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,192 KB
実行使用メモリ 244,272 KB
最終ジャッジ日時 2024-05-04 06:43:53
合計ジャッジ時間 14,085 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,376 KB
testcase_01 AC 42 ms
53,760 KB
testcase_02 AC 43 ms
53,684 KB
testcase_03 AC 43 ms
54,684 KB
testcase_04 WA -
testcase_05 AC 47 ms
54,648 KB
testcase_06 AC 44 ms
55,792 KB
testcase_07 AC 44 ms
53,412 KB
testcase_08 AC 44 ms
54,276 KB
testcase_09 AC 43 ms
55,104 KB
testcase_10 WA -
testcase_11 AC 46 ms
55,068 KB
testcase_12 AC 43 ms
53,624 KB
testcase_13 WA -
testcase_14 AC 43 ms
54,516 KB
testcase_15 AC 44 ms
54,456 KB
testcase_16 AC 44 ms
54,120 KB
testcase_17 AC 43 ms
54,300 KB
testcase_18 AC 43 ms
54,536 KB
testcase_19 AC 44 ms
54,072 KB
testcase_20 AC 43 ms
54,068 KB
testcase_21 AC 43 ms
55,656 KB
testcase_22 AC 44 ms
54,000 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 1,853 ms
244,244 KB
testcase_30 WA -
testcase_31 AC 1,835 ms
244,272 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
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), (0,-1), (0,1), (1,0)]
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