結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
AEn
|
| 提出日時 | 2022-08-31 13:59:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,129 bytes |
| コンパイル時間 | 444 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 192,108 KB |
| 最終ジャッジ日時 | 2024-11-08 05:38:00 |
| 合計ジャッジ時間 | 11,751 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 6 TLE * 2 -- * 11 |
ソースコード
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])
AEn