結果

問題 No.697 池の数はいくつか
ユーザー ayaoniayaoni
提出日時 2020-12-10 07:00:29
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,076 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 373,028 KB
最終ジャッジ日時 2024-05-04 07:16:27
合計ジャッジ時間 13,146 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,396 KB
testcase_01 AC 36 ms
53,944 KB
testcase_02 AC 36 ms
54,476 KB
testcase_03 AC 38 ms
54,972 KB
testcase_04 AC 40 ms
55,064 KB
testcase_05 AC 39 ms
54,724 KB
testcase_06 AC 38 ms
54,448 KB
testcase_07 AC 38 ms
54,564 KB
testcase_08 AC 35 ms
54,336 KB
testcase_09 AC 40 ms
54,056 KB
testcase_10 AC 36 ms
54,408 KB
testcase_11 AC 38 ms
54,632 KB
testcase_12 AC 36 ms
55,880 KB
testcase_13 AC 37 ms
54,956 KB
testcase_14 AC 41 ms
54,060 KB
testcase_15 AC 38 ms
54,392 KB
testcase_16 AC 37 ms
56,300 KB
testcase_17 AC 36 ms
55,512 KB
testcase_18 AC 36 ms
54,384 KB
testcase_19 AC 35 ms
53,988 KB
testcase_20 AC 36 ms
55,980 KB
testcase_21 AC 36 ms
54,548 KB
testcase_22 AC 41 ms
54,452 KB
testcase_23 AC 40 ms
54,460 KB
testcase_24 AC 229 ms
94,200 KB
testcase_25 AC 233 ms
94,424 KB
testcase_26 AC 222 ms
94,584 KB
testcase_27 AC 224 ms
94,264 KB
testcase_28 AC 246 ms
94,280 KB
testcase_29 MLE -
testcase_30 AC 1,453 ms
237,548 KB
testcase_31 MLE -
testcase_32 AC 1,433 ms
237,240 KB
testcase_33 AC 1,425 ms
237,484 KB
testcase_34 AC 1,366 ms
237,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())


H,W = MI()
A = [LI() for _ in range(H)]

flag = [[0]*W for _ in range(H)]
directions = [(-1,0),(1,0),(0,-1),(0,1)]
ans = 0
for i in range(H):
    for j in range(W):
        if flag[i][j] == 1 or A[i][j] == 0:
            continue
        ans += 1
        deq = deque([(i,j)])
        flag[i][j] = 1
        while deq:
            x,y = deq.pop()
            for dx,dy in directions:
                nx,ny = x+dx,y+dy
                if 0 <= nx < H and 0 <= ny < W and flag[nx][ny] == 0 and A[nx][ny] == 1:
                    flag[nx][ny] = 1
                    deq.append((nx,ny))

print(ans)
0