結果

問題 No.697 池の数はいくつか
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-22 16:16:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,689 ms / 6,000 ms
コード長 704 bytes
コンパイル時間 912 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 282,080 KB
最終ジャッジ日時 2024-06-01 17:59:06
合計ジャッジ時間 16,300 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,504 KB
testcase_01 AC 44 ms
54,272 KB
testcase_02 AC 43 ms
53,760 KB
testcase_03 AC 43 ms
53,760 KB
testcase_04 AC 43 ms
54,144 KB
testcase_05 AC 44 ms
53,632 KB
testcase_06 AC 45 ms
53,888 KB
testcase_07 AC 44 ms
54,144 KB
testcase_08 AC 42 ms
53,940 KB
testcase_09 AC 43 ms
53,888 KB
testcase_10 AC 44 ms
53,632 KB
testcase_11 AC 43 ms
53,888 KB
testcase_12 AC 42 ms
53,760 KB
testcase_13 AC 45 ms
53,760 KB
testcase_14 AC 42 ms
54,016 KB
testcase_15 AC 43 ms
53,632 KB
testcase_16 AC 42 ms
53,760 KB
testcase_17 AC 43 ms
54,144 KB
testcase_18 AC 44 ms
53,632 KB
testcase_19 AC 42 ms
53,632 KB
testcase_20 AC 43 ms
54,144 KB
testcase_21 AC 43 ms
54,016 KB
testcase_22 AC 42 ms
53,376 KB
testcase_23 AC 47 ms
53,632 KB
testcase_24 AC 250 ms
94,036 KB
testcase_25 AC 237 ms
94,080 KB
testcase_26 AC 242 ms
94,336 KB
testcase_27 AC 237 ms
94,124 KB
testcase_28 AC 270 ms
94,336 KB
testcase_29 AC 2,686 ms
281,360 KB
testcase_30 AC 1,329 ms
237,352 KB
testcase_31 AC 2,689 ms
282,080 KB
testcase_32 AC 1,346 ms
237,184 KB
testcase_33 AC 1,328 ms
237,096 KB
testcase_34 AC 1,359 ms
237,268 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