結果

問題 No.697 池の数はいくつか
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-22 15:53:38
言語 PyPy3
(7.3.13)
結果
MLE  
実行時間 -
コード長 556 bytes
コンパイル時間 388 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 844,820 KB
最終ジャッジ日時 2023-08-23 20:34:24
合計ジャッジ時間 11,876 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,376 KB
testcase_01 AC 70 ms
71,372 KB
testcase_02 AC 71 ms
71,236 KB
testcase_03 AC 70 ms
71,208 KB
testcase_04 AC 70 ms
71,112 KB
testcase_05 AC 71 ms
70,976 KB
testcase_06 AC 72 ms
71,392 KB
testcase_07 AC 71 ms
71,364 KB
testcase_08 AC 71 ms
71,332 KB
testcase_09 AC 70 ms
71,464 KB
testcase_10 AC 71 ms
71,376 KB
testcase_11 AC 71 ms
71,336 KB
testcase_12 AC 71 ms
70,980 KB
testcase_13 AC 70 ms
71,324 KB
testcase_14 AC 72 ms
71,108 KB
testcase_15 AC 73 ms
71,264 KB
testcase_16 AC 72 ms
71,120 KB
testcase_17 AC 69 ms
71,392 KB
testcase_18 AC 71 ms
71,460 KB
testcase_19 AC 70 ms
71,476 KB
testcase_20 AC 70 ms
71,380 KB
testcase_21 AC 71 ms
71,264 KB
testcase_22 AC 71 ms
70,972 KB
testcase_23 AC 71 ms
71,328 KB
testcase_24 AC 541 ms
100,420 KB
testcase_25 AC 543 ms
101,664 KB
testcase_26 AC 536 ms
103,000 KB
testcase_27 AC 547 ms
102,368 KB
testcase_28 AC 544 ms
101,516 KB
testcase_29 MLE -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
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]

def dfs(x,y):
    f[x][y] = cnt
    for i in range(4):
        if 0 <= x + l[i] < h and 0 <= y + r[i] < w:
            if grid[x+l[i]][y+r[i]] == 1 and f[x+l[i]][y+r[i]] == 0:
                dfs(x+l[i],y+r[i])


for i in range(h):
    for j in range(w):
        if grid[i][j] == 1 and f[i][j] ==0:
            dfs(i,j)
            cnt += 1
            
print(cnt-1) 
0