結果

問題 No.1283 Extra Fee
ユーザー vwxyzvwxyz
提出日時 2023-12-16 07:32:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,843 ms / 2,000 ms
コード長 868 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 102,468 KB
最終ジャッジ日時 2023-12-16 07:33:08
合計ジャッジ時間 19,922 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 41 ms
53,460 KB
testcase_03 AC 39 ms
53,460 KB
testcase_04 AC 40 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 42 ms
53,460 KB
testcase_07 AC 39 ms
53,460 KB
testcase_08 AC 43 ms
53,460 KB
testcase_09 AC 41 ms
53,460 KB
testcase_10 AC 41 ms
53,460 KB
testcase_11 AC 211 ms
78,260 KB
testcase_12 AC 229 ms
78,056 KB
testcase_13 AC 153 ms
77,056 KB
testcase_14 AC 271 ms
78,516 KB
testcase_15 AC 395 ms
80,268 KB
testcase_16 AC 174 ms
77,392 KB
testcase_17 AC 1,724 ms
101,744 KB
testcase_18 AC 1,167 ms
90,408 KB
testcase_19 AC 1,114 ms
89,368 KB
testcase_20 AC 1,068 ms
88,548 KB
testcase_21 AC 1,099 ms
88,820 KB
testcase_22 AC 983 ms
86,844 KB
testcase_23 AC 1,014 ms
84,892 KB
testcase_24 AC 1,024 ms
84,608 KB
testcase_25 AC 1,146 ms
89,380 KB
testcase_26 AC 1,184 ms
89,580 KB
testcase_27 AC 1,159 ms
89,580 KB
testcase_28 AC 1,174 ms
89,768 KB
testcase_29 AC 1,843 ms
102,468 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline
import heapq

N,M=map(int,readline().split())
C=[[0]*N for h in range(N)]
for m in range(M):
    h,w,c=map(int,readline().split())
    h-=1;w-=1
    C[h][w]=c
inf=1<<60
dist=[[[inf]*N for h in range(N)] for b in range(2)]
dist[0][0][0]=0
queue=[(0,0,0,0)]
while queue:
    dx,bx,hx,wx=heapq.heappop(queue)
    if dist[bx][hx][wx]<dx:
        continue
    for dh,dw in ((0,1),(1,0),(0,-1),(-1,0)):
        hy=hx+dh
        wy=wx+dw
        if 0<=hy<N and 0<=wy<N:
            if dist[bx][hy][wy]>dx+C[hy][wy]+1:
                dist[bx][hy][wy]=dx+C[hy][wy]+1
                heapq.heappush(queue,(dist[bx][hy][wy],bx,hy,wy))
            if bx==0:
                if dist[1][hy][wy]>dx+1:
                    dist[1][hy][wy]=dx+1
                    heapq.heappush(queue,(dist[1][hy][wy],1,hy,wy))
ans=dist[1][N-1][N-1]
print(ans)
0