結果

問題 No.697 池の数はいくつか
ユーザー ayaoniayaoni
提出日時 2020-12-10 07:00:29
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,076 bytes
コンパイル時間 1,201 ms
コンパイル使用メモリ 87,280 KB
実行使用メモリ 368,228 KB
最終ジャッジ日時 2023-08-16 23:52:01
合計ジャッジ時間 18,757 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,604 KB
testcase_01 AC 97 ms
71,832 KB
testcase_02 AC 96 ms
71,692 KB
testcase_03 AC 95 ms
71,568 KB
testcase_04 AC 93 ms
71,712 KB
testcase_05 AC 98 ms
71,620 KB
testcase_06 AC 93 ms
71,740 KB
testcase_07 AC 97 ms
71,912 KB
testcase_08 AC 96 ms
71,780 KB
testcase_09 AC 99 ms
71,564 KB
testcase_10 AC 98 ms
71,516 KB
testcase_11 AC 101 ms
71,684 KB
testcase_12 AC 98 ms
71,680 KB
testcase_13 AC 97 ms
71,820 KB
testcase_14 AC 96 ms
71,808 KB
testcase_15 AC 98 ms
71,620 KB
testcase_16 AC 98 ms
71,568 KB
testcase_17 AC 97 ms
71,412 KB
testcase_18 AC 96 ms
71,404 KB
testcase_19 AC 96 ms
71,600 KB
testcase_20 AC 98 ms
71,868 KB
testcase_21 AC 100 ms
71,420 KB
testcase_22 AC 96 ms
71,560 KB
testcase_23 AC 94 ms
71,404 KB
testcase_24 AC 322 ms
96,028 KB
testcase_25 AC 331 ms
95,984 KB
testcase_26 AC 316 ms
96,276 KB
testcase_27 AC 317 ms
95,876 KB
testcase_28 AC 338 ms
96,108 KB
testcase_29 MLE -
testcase_30 AC 1,802 ms
239,508 KB
testcase_31 MLE -
testcase_32 AC 1,746 ms
239,232 KB
testcase_33 AC 1,845 ms
239,348 KB
testcase_34 AC 1,651 ms
239,124 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