結果

問題 No.1283 Extra Fee
ユーザー mkawa2mkawa2
提出日時 2020-11-07 11:44:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,234 ms / 2,000 ms
コード長 863 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,220 KB
実行使用メモリ 120,648 KB
最終ジャッジ日時 2024-04-27 23:34:48
合計ジャッジ時間 16,510 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,444 KB
testcase_01 AC 34 ms
52,616 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 35 ms
52,888 KB
testcase_04 AC 40 ms
52,944 KB
testcase_05 AC 33 ms
53,916 KB
testcase_06 AC 34 ms
53,572 KB
testcase_07 AC 35 ms
53,240 KB
testcase_08 AC 36 ms
55,092 KB
testcase_09 AC 37 ms
53,576 KB
testcase_10 AC 36 ms
53,468 KB
testcase_11 AC 144 ms
79,480 KB
testcase_12 AC 202 ms
79,672 KB
testcase_13 AC 136 ms
78,280 KB
testcase_14 AC 262 ms
81,984 KB
testcase_15 AC 347 ms
85,060 KB
testcase_16 AC 164 ms
78,336 KB
testcase_17 AC 1,130 ms
117,568 KB
testcase_18 AC 1,082 ms
106,592 KB
testcase_19 AC 1,089 ms
107,052 KB
testcase_20 AC 982 ms
104,144 KB
testcase_21 AC 959 ms
104,884 KB
testcase_22 AC 922 ms
101,908 KB
testcase_23 AC 851 ms
103,024 KB
testcase_24 AC 879 ms
102,956 KB
testcase_25 AC 1,073 ms
107,900 KB
testcase_26 AC 1,072 ms
108,016 KB
testcase_27 AC 1,099 ms
107,316 KB
testcase_28 AC 1,090 ms
107,804 KB
testcase_29 AC 1,234 ms
120,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input = sys.stdin.buffer.readline

def MI(): return map(int, input().split())
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

from heapq import *

inf = 10**16
n, m = MI()
cc = [[0]*n for _ in range(n)]
for _ in range(m):
    i, j, c = MI()
    cc[i-1][j-1] = c

hp = []
dd = [[[inf]*2 for _ in range(n)] for _ in range(n)]
dd[0][0][0] = 0
heappush(hp, (0, 0, 0, 0))
while hp:
    d, i, j, k = heappop(hp)
    if (i,j)==(n-1,n-1):
        print(d)
        exit()
    if d > dd[i][j][k]: continue
    for di, dj in dij:
        ni, nj = i+di, j+dj
        if ni < 0 or ni >= n or nj < 0 or nj >= n: continue
        nd = d+cc[ni][nj]+1
        if nd < dd[ni][nj][k]:
            dd[ni][nj][k] = nd
            heappush(hp, (nd, ni, nj, k))
        if k == 0 and d+1 < dd[ni][nj][1]:
            dd[ni][nj][1] = d+1
            heappush(hp, (d+1, ni, nj, 1))
0