結果

問題 No.157 2つの空洞
ユーザー _matumo__matumo_
提出日時 2019-09-22 11:56:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 739 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,784 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-10-19 07:08:31
合計ジャッジ時間 1,472 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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=0
    for na in range(20):
        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-1
                    nb+=1
        if nb-na<2:     return 1
    return 1

print(fy())
0