結果

問題 No.1283 Extra Fee
ユーザー 👑 KazunKazun
提出日時 2020-11-06 23:00:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,730 ms / 2,000 ms
コード長 918 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,400 KB
実行使用メモリ 159,348 KB
最終ジャッジ日時 2024-04-27 23:26:18
合計ジャッジ時間 20,643 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
53,424 KB
testcase_01 AC 40 ms
52,956 KB
testcase_02 AC 41 ms
53,308 KB
testcase_03 AC 40 ms
52,816 KB
testcase_04 AC 41 ms
54,312 KB
testcase_05 AC 40 ms
53,080 KB
testcase_06 AC 42 ms
54,292 KB
testcase_07 AC 41 ms
54,188 KB
testcase_08 AC 43 ms
54,052 KB
testcase_09 AC 42 ms
54,496 KB
testcase_10 AC 41 ms
53,556 KB
testcase_11 AC 247 ms
81,616 KB
testcase_12 AC 224 ms
82,884 KB
testcase_13 AC 178 ms
80,316 KB
testcase_14 AC 300 ms
88,100 KB
testcase_15 AC 404 ms
95,724 KB
testcase_16 AC 188 ms
81,292 KB
testcase_17 AC 1,584 ms
153,020 KB
testcase_18 AC 1,171 ms
150,080 KB
testcase_19 AC 1,206 ms
151,848 KB
testcase_20 AC 1,244 ms
145,912 KB
testcase_21 AC 1,173 ms
147,516 KB
testcase_22 AC 1,113 ms
140,268 KB
testcase_23 AC 1,459 ms
139,632 KB
testcase_24 AC 1,481 ms
147,536 KB
testcase_25 AC 1,203 ms
153,724 KB
testcase_26 AC 1,192 ms
153,380 KB
testcase_27 AC 1,282 ms
154,760 KB
testcase_28 AC 1,196 ms
153,356 KB
testcase_29 AC 1,730 ms
159,348 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