結果

問題 No.1283 Extra Fee
ユーザー nok0nok0
提出日時 2020-09-05 19:22:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,523 ms / 2,000 ms
コード長 1,270 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 82,360 KB
実行使用メモリ 102,556 KB
最終ジャッジ日時 2024-04-27 23:07:34
合計ジャッジ時間 16,465 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,160 KB
testcase_01 AC 36 ms
53,640 KB
testcase_02 AC 38 ms
52,912 KB
testcase_03 AC 38 ms
53,620 KB
testcase_04 AC 37 ms
53,432 KB
testcase_05 AC 37 ms
53,256 KB
testcase_06 AC 40 ms
54,324 KB
testcase_07 AC 37 ms
54,000 KB
testcase_08 AC 35 ms
55,540 KB
testcase_09 AC 35 ms
53,780 KB
testcase_10 AC 36 ms
54,120 KB
testcase_11 AC 199 ms
79,296 KB
testcase_12 AC 182 ms
77,988 KB
testcase_13 AC 135 ms
77,064 KB
testcase_14 AC 239 ms
79,436 KB
testcase_15 AC 341 ms
80,488 KB
testcase_16 AC 162 ms
77,660 KB
testcase_17 AC 1,417 ms
101,272 KB
testcase_18 AC 919 ms
89,584 KB
testcase_19 AC 917 ms
88,792 KB
testcase_20 AC 883 ms
88,576 KB
testcase_21 AC 897 ms
88,752 KB
testcase_22 AC 786 ms
86,480 KB
testcase_23 AC 754 ms
85,216 KB
testcase_24 AC 755 ms
84,892 KB
testcase_25 AC 951 ms
90,272 KB
testcase_26 AC 942 ms
89,528 KB
testcase_27 AC 950 ms
88,900 KB
testcase_28 AC 996 ms
89,424 KB
testcase_29 AC 1,523 ms
102,556 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from heapq import heappush,heappop

readline = sys.stdin.buffer.readline

INF = int(1e15)
dh = [1,0,-1,0]
dw = [0,1,0,-1]

N, M = map(int,readline().split())
dist0 = [[INF for j in range(N)] for i in range(N)]
dist1 = [[INF for j in range(N)] for i in range(N)]
c = [[0 for j in range(N)] for i in range(N)]
dist0[0][0] = 0
dist1[0][0] = 0
for i in range(M):
    H, W, C = map(int,readline().split())
    H -= 1
    W -= 1
    c[H][W] = C

q = [(0,0,0,0)]
while q:
    C, H, W, used = heappop(q)
    if(used == 0 and dist0[H][W] < C):
        continue
    if(used == 1 and dist1[H][W] < C):
        continue
    for i in range(4):
        nH = H + dh[i]
        nW = W + dw[i]
        if(nH < 0 or nH >= N):
            continue
        if(nW < 0 or nW >= N):
            continue
        nC0 = C + c[nH][nW] + 1
        nC1 = C + 1
        if(used == 0):
            if(dist0[nH][nW] > nC0):
                heappush(q,(nC0,nH,nW,0))
                dist0[nH][nW] = nC0
            if(dist1[nH][nW] > nC1):
                heappush(q,(nC1,nH,nW,1))
                dist1[nH][nW] = nC1
        else:
            if(dist1[nH][nW] > nC0):
                heappush(q,(nC0,nH,nW,1))
                dist1[nH][nW] = nC0

print(min(dist0[N-1][N-1],dist1[N-1][N-1]))
0