結果

問題 No.2708 Jewel holder
ユーザー FromBooskaFromBooska
提出日時 2024-03-31 16:48:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,367 bytes
コンパイル時間 223 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 102,140 KB
最終ジャッジ日時 2024-03-31 16:48:44
合計ジャッジ時間 6,226 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
60,264 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 37 ms
53,460 KB
testcase_06 AC 37 ms
53,460 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 37 ms
53,460 KB
testcase_09 AC 47 ms
61,720 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 161 ms
77,448 KB
testcase_12 AC 38 ms
53,460 KB
testcase_13 AC 150 ms
77,396 KB
testcase_14 AC 63 ms
70,192 KB
testcase_15 AC 1,230 ms
84,180 KB
testcase_16 AC 97 ms
76,260 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 盤面が非常に小さい、visited管理してDFSにしよう
# 問題文では「没収されるときに1つも宝石を持っていない状況」とあるが0個になるのはOKなのか
# 動きが上下左右だけというのも書いてない

H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(input())
    
import sys
sys.setrecursionlimit(10**7)

def dfs(ch, cw, step, coin):
    #print('ch', ch, 'cw', cw, 'step', step, 'coin', coin)
    #print('visited', visited)
    #print()
    
    global ans_list
    if (ch, cw)==(H-1, W-1):
        ans_list.append(step)
        return
    
    for dh, dw in d:
        if 0 <= ch+dh < H and 0 <= cw+dw < W and visited[ch+dh][cw+dw ]==0:
            if A[ch+dh][cw+dw] == 'o':
                visited[ch+dh][cw+dw ]=1
                dfs(ch+dh, cw+dw, step+1, coin+1)
                visited[ch+dh][cw+dw ]=0
            elif A[ch+dh][cw+dw] == 'x':
                if coin>=1:
                    visited[ch+dh][cw+dw ]=1
                    dfs(ch+dh, cw+dw, step+1, coin-1)
                    visited[ch+dh][cw+dw ]=0
    
d = [[+1, 0], [-1, 0], [0, +1], [0, -1]]
ans_list = []
visited = [[0]*W for i in range(H)]
visited[0][0] = 1
dfs(0, 0, 0, 1)
#print(ans_list)

if len(ans_list)>0:
    min_step = min(ans_list)
    ans = ans_list.count(min_step)
else:
    ans = 0
print(ans)
    
0