結果

問題 No.1283 Extra Fee
ユーザー 👑 KazunKazun
提出日時 2020-11-06 23:00:52
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,739 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 160,860 KB
最終ジャッジ日時 2023-08-10 06:08:24
合計ジャッジ時間 21,687 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,680 KB
testcase_01 AC 73 ms
71,380 KB
testcase_02 AC 73 ms
71,216 KB
testcase_03 AC 72 ms
71,144 KB
testcase_04 AC 74 ms
71,516 KB
testcase_05 AC 73 ms
71,524 KB
testcase_06 AC 73 ms
71,668 KB
testcase_07 AC 73 ms
71,492 KB
testcase_08 AC 75 ms
71,552 KB
testcase_09 AC 74 ms
71,488 KB
testcase_10 AC 73 ms
71,140 KB
testcase_11 AC 283 ms
84,160 KB
testcase_12 AC 258 ms
84,492 KB
testcase_13 AC 209 ms
81,640 KB
testcase_14 AC 328 ms
90,924 KB
testcase_15 AC 423 ms
98,008 KB
testcase_16 AC 219 ms
82,704 KB
testcase_17 AC 1,565 ms
155,240 KB
testcase_18 AC 1,186 ms
150,800 KB
testcase_19 AC 1,219 ms
152,432 KB
testcase_20 AC 1,122 ms
147,484 KB
testcase_21 AC 1,091 ms
148,332 KB
testcase_22 AC 1,054 ms
142,364 KB
testcase_23 AC 1,391 ms
141,728 KB
testcase_24 AC 1,452 ms
149,472 KB
testcase_25 AC 1,247 ms
154,432 KB
testcase_26 AC 1,168 ms
154,972 KB
testcase_27 AC 1,264 ms
155,424 KB
testcase_28 AC 1,171 ms
155,512 KB
testcase_29 AC 1,739 ms
160,860 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

Flag=[[[False,False] for _ in range(N+1)] for __ in range(N+1)]

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

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

    i,j,m=v
    if Flag[i][j][m]:
        continue

    Flag[i][j][m]=True

    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