結果

問題 No.2708 Jewel holder
ユーザー かもめのうでかもめのうで
提出日時 2024-03-31 14:35:51
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 853 bytes
コンパイル時間 143 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 55,612 KB
最終ジャッジ日時 2024-03-31 14:35:53
合計ジャッジ時間 1,587 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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