結果

問題 No.2708 Jewel holder
ユーザー かもめのうで
提出日時 2024-03-31 14:35:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 213 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 55,620 KB
最終ジャッジ日時 2024-09-30 19:43:42
合計ジャッジ時間 1,864 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

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

from collections import deque
dij = [(1, 0), (0, 1)]

q = deque()
visited = [[0]*w for _ in range(h)]
dist = [[1<<60]*w for _ in range(h)]
q.append((1, 0, 0))
visited[0][0] = 1
dist[0][0] = 0 


while q:
    t, i, j = q.popleft()
    for di, dj in dij:
        ni = di+i
        nj = dj+j
        nt = t

        if not (0<=ni<h and 0<=nj<w and a[ni][nj] != "#"):
            continue
        if dist[ni][nj] < dist[i][j] + 1:
            continue

        if a[ni][nj] == "x":
            nt -= 1
        else:
            nt += 1
        if nt < 0:
            continue
        
        if dist[ni][nj] > dist[i][j]+1:
            q.append((nt, ni, nj))
            dist[ni][nj] = min(dist[ni][nj], dist[i][j]+1)
        visited[ni][nj] += visited[i][j]

print(visited[h-1][w-1])
0