結果

問題 No.1283 Extra Fee
ユーザー 👑 platinumplatinum
提出日時 2020-09-05 00:59:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,159 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 56,152 KB
最終ジャッジ日時 2024-05-05 04:03:38
合計ジャッジ時間 17,949 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 446 ms
49,756 KB
testcase_01 AC 446 ms
43,864 KB
testcase_02 AC 450 ms
44,124 KB
testcase_03 AC 450 ms
43,864 KB
testcase_04 AC 450 ms
43,860 KB
testcase_05 AC 452 ms
43,864 KB
testcase_06 AC 455 ms
43,868 KB
testcase_07 AC 446 ms
44,380 KB
testcase_08 AC 466 ms
43,992 KB
testcase_09 AC 461 ms
44,124 KB
testcase_10 AC 456 ms
44,120 KB
testcase_11 AC 730 ms
43,864 KB
testcase_12 AC 821 ms
43,992 KB
testcase_13 AC 683 ms
44,120 KB
testcase_14 AC 1,499 ms
44,116 KB
testcase_15 TLE -
testcase_16 AC 783 ms
44,380 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush,heappop
import numpy as np

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

N, M = map(int,input().split())
dist0 = np.full((N,N),INF)
dist1 = np.full((N,N),INF)
c = np.zeros((N,N))
dist0[0][0] = 0
dist1[0][0] = 0
for i in range(M):
    H, W, C = map(int,input().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