結果

問題 No.697 池の数はいくつか
ユーザー lllllll88938494lllllll88938494
提出日時 2022-09-22 15:46:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 556 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 10,736 KB
実行使用メモリ 498,744 KB
最終ジャッジ日時 2023-08-23 20:33:57
合計ジャッジ時間 16,879 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
12,224 KB
testcase_01 AC 15 ms
7,800 KB
testcase_02 AC 16 ms
7,776 KB
testcase_03 AC 16 ms
7,860 KB
testcase_04 AC 16 ms
7,772 KB
testcase_05 AC 16 ms
7,836 KB
testcase_06 AC 16 ms
7,784 KB
testcase_07 AC 16 ms
7,912 KB
testcase_08 AC 15 ms
7,844 KB
testcase_09 AC 15 ms
7,928 KB
testcase_10 AC 15 ms
7,928 KB
testcase_11 AC 15 ms
7,888 KB
testcase_12 AC 15 ms
7,732 KB
testcase_13 AC 15 ms
7,748 KB
testcase_14 AC 16 ms
7,864 KB
testcase_15 AC 15 ms
7,832 KB
testcase_16 AC 15 ms
7,932 KB
testcase_17 AC 16 ms
7,924 KB
testcase_18 AC 15 ms
7,780 KB
testcase_19 AC 16 ms
7,912 KB
testcase_20 AC 15 ms
7,932 KB
testcase_21 AC 16 ms
7,748 KB
testcase_22 AC 15 ms
7,844 KB
testcase_23 AC 16 ms
7,864 KB
testcase_24 AC 1,063 ms
26,964 KB
testcase_25 AC 1,057 ms
26,928 KB
testcase_26 AC 1,061 ms
27,080 KB
testcase_27 AC 1,058 ms
27,112 KB
testcase_28 AC 1,059 ms
27,072 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