結果

問題 No.157 2つの空洞
ユーザー _matumo__matumo_
提出日時 2019-09-26 16:46:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 707 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 11,820 KB
実行使用メモリ 10,152 KB
最終ジャッジ日時 2023-10-24 15:35:05
合計ジャッジ時間 1,498 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,148 KB
testcase_01 AC 27 ms
10,148 KB
testcase_02 AC 28 ms
10,148 KB
testcase_03 AC 27 ms
10,148 KB
testcase_04 AC 28 ms
10,148 KB
testcase_05 AC 28 ms
10,152 KB
testcase_06 AC 27 ms
10,152 KB
testcase_07 AC 27 ms
10,148 KB
testcase_08 AC 27 ms
10,148 KB
testcase_09 AC 27 ms
10,152 KB
testcase_10 AC 27 ms
10,148 KB
testcase_11 AC 27 ms
10,148 KB
testcase_12 AC 28 ms
10,152 KB
testcase_13 AC 27 ms
10,152 KB
testcase_14 AC 27 ms
10,152 KB
testcase_15 AC 29 ms
10,152 KB
testcase_16 AC 28 ms
10,152 KB
testcase_17 AC 28 ms
10,152 KB
testcase_18 AC 28 ms
10,152 KB
testcase_19 AC 29 ms
10,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

W,H=map(int,input().split())
pa=[[[0,1][x=='.'] for x in input()] for y in range(H)]

def fx(y,x,na,nb):
    if not 0<=y<H:      return 0
    if not 0<=x<W:      return 0
    n=pa[y][x]
    if n>=nb:           return 0
    if n> na:           return 1
    pa[y][x]=nb
    if n<=0:            return 0
    if fx(y-1,x,na,nb): return 1
    if fx(y+1,x,na,nb): return 1
    if fx(y,x-1,na,nb): return 1
    if fx(y,x+1,na,nb): return 1
    return 0

def fy():
    nb=2
    for na in range(1,40):
        for y in range(H):
            for x in range(W):
                n=pa[y][x]
                if n==na:
                    if fx(y,x,na,nb):   return nb-2
                    nb+=1
    return 1

print(fy())
0