結果

問題 No.697 池の数はいくつか
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-22 16:16:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,909 ms / 6,000 ms
コード長 704 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 285,180 KB
最終ジャッジ日時 2023-08-23 20:35:47
合計ジャッジ時間 18,407 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,676 KB
testcase_01 AC 92 ms
71,708 KB
testcase_02 AC 91 ms
71,604 KB
testcase_03 AC 93 ms
71,620 KB
testcase_04 AC 91 ms
71,672 KB
testcase_05 AC 91 ms
71,512 KB
testcase_06 AC 92 ms
71,464 KB
testcase_07 AC 92 ms
71,644 KB
testcase_08 AC 91 ms
71,828 KB
testcase_09 AC 91 ms
71,728 KB
testcase_10 AC 91 ms
71,600 KB
testcase_11 AC 90 ms
71,472 KB
testcase_12 AC 92 ms
71,648 KB
testcase_13 AC 94 ms
71,320 KB
testcase_14 AC 92 ms
71,464 KB
testcase_15 AC 90 ms
71,480 KB
testcase_16 AC 90 ms
71,328 KB
testcase_17 AC 90 ms
71,636 KB
testcase_18 AC 90 ms
71,744 KB
testcase_19 AC 91 ms
71,580 KB
testcase_20 AC 92 ms
71,632 KB
testcase_21 AC 91 ms
71,768 KB
testcase_22 AC 90 ms
71,324 KB
testcase_23 AC 90 ms
71,468 KB
testcase_24 AC 304 ms
95,824 KB
testcase_25 AC 292 ms
95,616 KB
testcase_26 AC 297 ms
95,892 KB
testcase_27 AC 295 ms
95,948 KB
testcase_28 AC 316 ms
96,184 KB
testcase_29 AC 2,813 ms
285,172 KB
testcase_30 AC 1,413 ms
238,776 KB
testcase_31 AC 2,909 ms
285,180 KB
testcase_32 AC 1,426 ms
238,836 KB
testcase_33 AC 1,429 ms
238,852 KB
testcase_34 AC 1,416 ms
238,692 KB
権限があれば一括ダウンロードができます

ソースコード

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:
            d=deque()
            d.append((i,j))
            grid[i][j] = 0
            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:
                            grid[x+l[k]][y+r[k]] = 0
                            d.append((x+l[k],y+r[k]))
            cnt+=1
print(cnt-1) 

0