結果

問題 No.2708 Jewel holder
ユーザー lloyz
提出日時 2024-05-09 22:13:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 82,600 KB
実行使用メモリ 69,204 KB
最終ジャッジ日時 2024-12-17 16:30:40
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

h, w = map(int, input().split())
A = [list(input()) for _ in range(h)]

D = [(1, 0), (0, 1)]
Que = deque([(1, 0, 0)])
ans = 0
while Que:
    cc, ci, cj = Que.popleft()
    if ci == h - 1 and cj == w - 1:
        ans += 1
        continue
    for di, dj in D:
        ni, nj = ci + di, cj + dj
        if 0 <= ni < h and 0 <= nj < w:
            if A[ni][nj] == '#':
                continue
            if A[ni][nj] == 'o':
                nc = cc + 1
            else:
                nc = cc - 1
                if nc == -1:
                    continue
            Que.append((nc, ni, nj))
print(ans)
0