結果

問題 No.697 池の数はいくつか
ユーザー titiatitia
提出日時 2023-10-12 02:21:06
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 539 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 514,328 KB
最終ジャッジ日時 2023-10-12 02:21:28
合計ジャッジ時間 18,660 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,260 KB
testcase_01 AC 77 ms
71,332 KB
testcase_02 AC 77 ms
71,224 KB
testcase_03 AC 75 ms
71,436 KB
testcase_04 AC 74 ms
71,064 KB
testcase_05 AC 75 ms
71,412 KB
testcase_06 AC 75 ms
71,368 KB
testcase_07 AC 76 ms
71,252 KB
testcase_08 AC 76 ms
71,300 KB
testcase_09 AC 76 ms
71,096 KB
testcase_10 AC 76 ms
71,224 KB
testcase_11 AC 77 ms
71,296 KB
testcase_12 AC 76 ms
71,200 KB
testcase_13 AC 76 ms
71,196 KB
testcase_14 AC 76 ms
71,100 KB
testcase_15 AC 76 ms
71,264 KB
testcase_16 AC 77 ms
71,400 KB
testcase_17 AC 75 ms
71,264 KB
testcase_18 AC 76 ms
71,352 KB
testcase_19 AC 77 ms
71,264 KB
testcase_20 AC 77 ms
71,224 KB
testcase_21 AC 76 ms
71,476 KB
testcase_22 AC 77 ms
71,204 KB
testcase_23 AC 76 ms
71,528 KB
testcase_24 AC 329 ms
95,268 KB
testcase_25 AC 306 ms
95,152 KB
testcase_26 AC 305 ms
95,012 KB
testcase_27 AC 320 ms
95,120 KB
testcase_28 AC 304 ms
95,192 KB
testcase_29 MLE -
testcase_30 AC 1,707 ms
238,428 KB
testcase_31 MLE -
testcase_32 AC 1,721 ms
238,792 KB
testcase_33 AC 1,787 ms
238,736 KB
testcase_34 AC 1,741 ms
238,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
A=[list(map(int,input().split())) for i in range(H)]

ANS=0
USE=[[0]*W for i in range(H)]

for i in range(H):
    for j in range(W):
        if A[i][j]==1 and USE[i][j]==0:
            ANS+=1
            Q=[(i,j)]
            USE[i][j]=1
            while Q:
                x,y=Q.pop()
                for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
                    if 0<=z<H and 0<=w<W and A[z][w]==1 and USE[z][w]==0:
                        USE[z][w]=1
                        Q.append((z,w))

print(ANS)
0