結果

問題 No.1283 Extra Fee
ユーザー brthyyjpbrthyyjp
提出日時 2020-11-06 22:17:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,437 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 86,808 KB
実行使用メモリ 272,032 KB
最終ジャッジ日時 2023-09-29 18:58:52
合計ジャッジ時間 5,782 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
75,620 KB
testcase_01 AC 73 ms
71,188 KB
testcase_02 AC 100 ms
77,096 KB
testcase_03 AC 74 ms
70,936 KB
testcase_04 AC 75 ms
71,244 KB
testcase_05 AC 73 ms
70,936 KB
testcase_06 AC 163 ms
78,540 KB
testcase_07 AC 76 ms
71,328 KB
testcase_08 AC 159 ms
78,152 KB
testcase_09 AC 145 ms
78,476 KB
testcase_10 AC 140 ms
78,416 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
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 #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
HWC = []
A = [[0]*n for _ in range(n)]
for i in range(m):
    h, w, c = map(int, input().split())
    h, w =h-1, w-1
    HWC.append((h, w, c))
    A[h][w] = c

import heapq
INF = 10**18
def dijkstra_heap(s, edge):
    n = len(edge)
    d = [INF] * n
    used = [True] * n #True: not used
    d[s] = 0
    used[s] = False
    edgelist = []
    for e in edge[s]:
        heapq.heappush(edgelist,e)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        if not used[minedge[1]]:
            continue
        v = minedge[1]
        d[v] = minedge[0]
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v],e[1]))
    return d

ans = INF
for p in range(m):
    B = [[0]*n for _ in range(n)]
    for i in range(n):
        for j in range(n):
            B[i][j] = A[i][j]
    h, w, _ = HWC[p]
    B[h][w] = 0
    g = [[] for _ in range(n**2)]
    for i in range(n):
        for j in range(n):
            v = i*n+j
            for di, dj in (-1, 0), (1, 0), (0, 1), (0, -1):
                ni, nj = i+di, j+dj
                if 0 <= ni < n and 0 <= nj < n:
                    c = B[ni][nj]+1
                    u = ni*n+nj
                    g[v].append((c, u))
    d = dijkstra_heap(0, g)
    ans = min(ans, d[-1])
print(ans)
0