結果

問題 No.2708 Jewel holder
ユーザー かもめのうで
提出日時 2024-03-31 21:53:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 439 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 68,608 KB
最終ジャッジ日時 2024-09-30 21:26:30
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
# どのように行っても最短路
dij = [(1, 0), (0, 1)]

ans = 0
stack = [(1, 0, 0)]
while stack:
    t, i, j = stack.pop()
    for di, dj in dij:
        ni = i+di
        nj = j+dj
        nt = t
        if not(0<=ni<h and 0<=nj<w and a[ni][nj] != "#"):
            continue

        if a[ni][nj] == "o":
            nt += 1
        else:
            nt -= 1
        if nt < 0:
            continue

        if ni == h-1 and nj == w-1:
            ans += 1
        else:
            stack.append((nt, ni, nj))
print(ans)
0