結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,580 KB
testcase_01 AC 76 ms
71,304 KB
testcase_02 AC 75 ms
71,308 KB
testcase_03 AC 82 ms
71,156 KB
testcase_04 AC 76 ms
71,264 KB
testcase_05 AC 76 ms
71,484 KB
testcase_06 AC 76 ms
71,240 KB
testcase_07 AC 76 ms
71,340 KB
testcase_08 AC 77 ms
71,272 KB
testcase_09 AC 78 ms
71,468 KB
testcase_10 AC 77 ms
71,236 KB
testcase_11 AC 76 ms
71,412 KB
testcase_12 AC 77 ms
71,548 KB
testcase_13 AC 76 ms
71,240 KB
testcase_14 AC 75 ms
71,268 KB
testcase_15 AC 76 ms
71,544 KB
testcase_16 AC 77 ms
71,144 KB
testcase_17 AC 76 ms
71,588 KB
testcase_18 AC 78 ms
71,188 KB
testcase_19 AC 76 ms
71,480 KB
testcase_20 AC 75 ms
71,320 KB
testcase_21 AC 77 ms
71,332 KB
testcase_22 AC 77 ms
71,244 KB
testcase_23 AC 76 ms
71,412 KB
testcase_24 AC 317 ms
120,616 KB
testcase_25 AC 311 ms
120,540 KB
testcase_26 AC 324 ms
120,268 KB
testcase_27 AC 306 ms
120,332 KB
testcase_28 AC 310 ms
120,456 KB
testcase_29 MLE -
testcase_30 AC 1,931 ms
292,576 KB
testcase_31 MLE -
testcase_32 AC 1,996 ms
293,556 KB
testcase_33 AC 1,843 ms
293,368 KB
testcase_34 AC 1,920 ms
292,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

ANS=0
USE=[0]*(H*W)

for i in range(H):
    for j in range(W):
        if A[i*W+j]==1 and USE[i*W+j]==0:
            ANS+=1
            Q=[(i,j)]
            USE[i*W+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+w]==1 and USE[z*W+w]==0:
                        USE[z*W+w]=1
                        Q.append((z,w))

print(ANS)
0