結果

問題 No.1283 Extra Fee
ユーザー AEnAEn
提出日時 2022-08-31 13:59:27
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,129 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 82,924 KB
実行使用メモリ 203,400 KB
最終ジャッジ日時 2024-04-25 18:12:03
合計ジャッジ時間 10,986 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
62,048 KB
testcase_01 AC 38 ms
55,756 KB
testcase_02 AC 41 ms
55,596 KB
testcase_03 AC 36 ms
54,664 KB
testcase_04 AC 37 ms
54,320 KB
testcase_05 AC 37 ms
55,396 KB
testcase_06 WA -
testcase_07 AC 37 ms
54,608 KB
testcase_08 AC 39 ms
55,756 KB
testcase_09 AC 37 ms
55,536 KB
testcase_10 AC 39 ms
55,116 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 218 ms
84,068 KB
testcase_17 AC 1,942 ms
134,888 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
from collections import defaultdict

N, M = map(int, input().split())
d = defaultdict(int)
s = set()
for i in range(M):
    h, w, c = map(int, input().split())
    h-=1;w-=1
    s.add((h, w))
    d[str(h)+'_'+str(w)] = c
cost = [[[float('inf'), 0] for _ in range(N)] for _ in range(N)]
cost[0][0][0] = 0
q = deque()
q.append((0, 0))
xx = [0,1,0,-1]
yy = [1,0,-1,0]
while q:
    x, y = q.popleft()
    for px, py in zip(xx, yy):
        cx = x+px
        cy = y+py
        if 0<=cx<N and 0<=cy<N:
            if (cx, cy) in s:
                c = d[str(cx)+'_'+str(cy)]
                if cost[cx][cy][0]-cost[cx][cy][1]>cost[x][y][0]+1+c-max(cost[x][y][1], c):
                    cost[cx][cy][0] = cost[x][y][0]+1+c
                    cost[cx][cy][1] = max(cost[x][y][1], c)
                    q.append((cx, cy))
            else:
                if cost[cx][cy][0]-cost[cx][cy][1]>cost[x][y][0]+1-cost[x][y][1]:
                    cost[cx][cy][0] = cost[x][y][0]+1
                    cost[cx][cy][1] = cost[x][y][1]
                    q.append((cx, cy))
print(cost[-1][-1][0]-cost[-1][-1][1])
0