結果

問題 No.2708 Jewel holder
コンテスト
ユーザー LyricalMaestro
提出日時 2026-03-09 23:48:03
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 893 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 711 ms
コンパイル使用メモリ 20,828 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-03-09 23:48:12
合計ジャッジ時間 3,480 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

## https://yukicoder.me/problems/no/2708


def main():
    H, W = map(int, input().split())
    A = []
    for _ in range(H):
        A.append(input())

    answer = 0

    def dfs(H, W, A, pos_h, pos_w, jewel):
        if (pos_h, pos_w) == (H - 1, W - 1):
            return 1
        
        answer = 0
        for dh, dw in ((0, 1), (1, 0)):
            new_h = dh + pos_h
            new_w = dw + pos_w
            if 0 <= new_h < H and 0 <= new_w < W:
                if A[new_h][new_w] == "#":
                    continue
                elif A[new_h][new_w] == "o":
                    answer += dfs(H, W, A, new_h, new_w, jewel + 1)
                else:
                    if jewel >= 1:
                        answer += dfs(H, W, A, new_h, new_w, jewel - 1)
        return answer
    
    answer = dfs(H, W, A, 0, 0, 1)
    print(answer)




if __name__ == "__main__":
    main()
0