結果

問題 No.1283 Extra Fee
ユーザー 👑 KazunKazun
提出日時 2020-11-07 00:05:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,308 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 126 ms
コンパイル使用メモリ 82,104 KB
実行使用メモリ 136,964 KB
最終ジャッジ日時 2024-04-27 23:27:39
合計ジャッジ時間 14,521 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,092 KB
testcase_01 AC 33 ms
53,496 KB
testcase_02 AC 37 ms
53,536 KB
testcase_03 AC 39 ms
53,716 KB
testcase_04 AC 34 ms
53,400 KB
testcase_05 AC 32 ms
52,808 KB
testcase_06 AC 35 ms
54,460 KB
testcase_07 AC 35 ms
54,416 KB
testcase_08 AC 36 ms
53,744 KB
testcase_09 AC 34 ms
53,628 KB
testcase_10 AC 34 ms
52,956 KB
testcase_11 AC 206 ms
80,640 KB
testcase_12 AC 152 ms
80,056 KB
testcase_13 AC 138 ms
79,232 KB
testcase_14 AC 225 ms
84,708 KB
testcase_15 AC 289 ms
89,876 KB
testcase_16 AC 149 ms
79,340 KB
testcase_17 AC 1,291 ms
133,228 KB
testcase_18 AC 771 ms
128,840 KB
testcase_19 AC 793 ms
130,328 KB
testcase_20 AC 726 ms
125,828 KB
testcase_21 AC 753 ms
126,940 KB
testcase_22 AC 669 ms
121,520 KB
testcase_23 AC 1,009 ms
117,228 KB
testcase_24 AC 1,099 ms
125,776 KB
testcase_25 AC 772 ms
131,624 KB
testcase_26 AC 800 ms
131,372 KB
testcase_27 AC 814 ms
131,924 KB
testcase_28 AC 815 ms
131,948 KB
testcase_29 AC 1,308 ms
136,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,heapq
input=sys.stdin.readline

N,M=map(int,input().split())
inf=float("inf")

F=[[1]*(N+1) for _ in range(N+1)]
for _ in range(M):
    h,w,c=map(int,input().split())
    F[h][w]+=c

V=[(1,0),(-1,0),(0,1),(0,-1)]

Dist=[[[inf,inf] for _ in range(N+1)] for __ in range(N+1)]
Dist[1][1][0]=0

Q=[(0,(1,1,0))]
heapq.heapify(Q)

while Q:
    d,v=heapq.heappop(Q)

    i,j,m=v
    if d<Dist[i][j][m]:
        continue

    if i==j==N:
        break

    for (a,b) in V:
        if 1<=i+a<=N and 1<=j+b<=N:
            if d+F[i+a][j+b]<Dist[i+a][j+b][m]:
                Dist[i+a][j+b][m]=d+F[i+a][j+b]
                heapq.heappush(Q,(d+F[i+a][j+b],(i+a,j+b,m)))

            if m==0 and d+1<Dist[i+a][j+b][1]:
                Dist[i+a][j+b][1]=d+1
                heapq.heappush(Q,(d+1,(i+a,j+b,1)))

print(min(Dist[N][N]))
0