結果

問題 No.697 池の数はいくつか
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-22 16:11:25
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 667 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 437,984 KB
最終ジャッジ日時 2024-06-01 17:58:49
合計ジャッジ時間 14,778 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,004 KB
testcase_01 AC 42 ms
54,652 KB
testcase_02 AC 42 ms
55,100 KB
testcase_03 AC 43 ms
54,628 KB
testcase_04 AC 42 ms
54,148 KB
testcase_05 AC 42 ms
54,740 KB
testcase_06 AC 42 ms
54,404 KB
testcase_07 AC 42 ms
55,184 KB
testcase_08 AC 41 ms
55,164 KB
testcase_09 AC 41 ms
54,532 KB
testcase_10 AC 42 ms
54,716 KB
testcase_11 AC 42 ms
54,332 KB
testcase_12 AC 42 ms
54,684 KB
testcase_13 AC 42 ms
55,112 KB
testcase_14 AC 42 ms
54,932 KB
testcase_15 AC 43 ms
55,104 KB
testcase_16 AC 42 ms
55,160 KB
testcase_17 AC 42 ms
54,364 KB
testcase_18 AC 41 ms
53,996 KB
testcase_19 AC 42 ms
54,524 KB
testcase_20 AC 43 ms
54,436 KB
testcase_21 AC 42 ms
55,252 KB
testcase_22 AC 42 ms
55,044 KB
testcase_23 AC 43 ms
54,616 KB
testcase_24 AC 4,475 ms
282,496 KB
testcase_25 MLE -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

h,w=map(int,input().split())
grid=[list(map(int,input().split())) for i in range(h)]
f=[[0]*w for i in range(h)]
cnt = 1
l=[1,0,-1,0]
r=[0,1,0,-1]


for i in range(h):
    for j in range(w):
        if grid[i][j] == 1 and f[i][j] ==0:
            d=deque()
            d.append((i,j))
            while d:
                x,y=d.popleft()
                f[x][y] = cnt
                for k in range(4):
                    if 0 <= x + l[k] < h and 0 <= y + r[k] < w:
                        if grid[x+l[k]][y+r[k]] == 1 and f[x+l[k]][y+r[k]] == 0:
                            d.append((x+l[k],y+r[k]))
            cnt+=1
print(cnt-1) 

0