結果

問題 No.1283 Extra Fee
ユーザー 👑 platinumplatinum
提出日時 2020-09-05 01:58:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,271 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 13,056 KB
実行使用メモリ 41,600 KB
最終ジャッジ日時 2024-05-05 04:04:09
合計ジャッジ時間 7,514 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
16,512 KB
testcase_01 AC 26 ms
11,136 KB
testcase_02 AC 26 ms
11,136 KB
testcase_03 AC 26 ms
11,008 KB
testcase_04 AC 31 ms
11,008 KB
testcase_05 AC 29 ms
11,008 KB
testcase_06 AC 29 ms
11,008 KB
testcase_07 AC 27 ms
11,264 KB
testcase_08 AC 27 ms
11,008 KB
testcase_09 AC 27 ms
11,008 KB
testcase_10 AC 27 ms
11,136 KB
testcase_11 AC 165 ms
12,416 KB
testcase_12 AC 196 ms
12,800 KB
testcase_13 AC 137 ms
12,160 KB
testcase_14 AC 503 ms
16,256 KB
testcase_15 AC 793 ms
19,328 KB
testcase_16 AC 180 ms
12,544 KB
testcase_17 TLE -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

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