結果

問題 No.2708 Jewel holder
ユーザー かもめのうでかもめのうで
提出日時 2024-03-31 21:53:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 70,424 KB
最終ジャッジ日時 2024-03-31 21:53:50
合計ジャッジ時間 1,836 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,460 KB
testcase_01 AC 41 ms
55,612 KB
testcase_02 AC 42 ms
53,460 KB
testcase_03 AC 47 ms
53,460 KB
testcase_04 AC 42 ms
53,460 KB
testcase_05 AC 41 ms
53,460 KB
testcase_06 AC 40 ms
53,460 KB
testcase_07 AC 41 ms
55,612 KB
testcase_08 AC 41 ms
55,612 KB
testcase_09 AC 42 ms
55,612 KB
testcase_10 AC 41 ms
53,460 KB
testcase_11 AC 43 ms
55,612 KB
testcase_12 AC 41 ms
53,460 KB
testcase_13 AC 42 ms
55,612 KB
testcase_14 AC 41 ms
55,612 KB
testcase_15 AC 42 ms
55,612 KB
testcase_16 AC 43 ms
55,612 KB
testcase_17 AC 66 ms
70,424 KB
testcase_18 AC 44 ms
55,612 KB
testcase_19 AC 42 ms
55,612 KB
権限があれば一括ダウンロードができます

ソースコード

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