結果

問題 No.1283 Extra Fee
ユーザー c-yanc-yan
提出日時 2020-11-06 23:13:42
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,146 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 86,692 KB
実行使用メモリ 178,436 KB
最終ジャッジ日時 2023-09-29 19:32:47
合計ジャッジ時間 23,637 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,648 KB
testcase_01 AC 92 ms
71,568 KB
testcase_02 AC 91 ms
71,492 KB
testcase_03 AC 91 ms
71,648 KB
testcase_04 AC 91 ms
71,488 KB
testcase_05 AC 92 ms
71,692 KB
testcase_06 WA -
testcase_07 AC 91 ms
71,492 KB
testcase_08 AC 95 ms
71,596 KB
testcase_09 WA -
testcase_10 AC 100 ms
71,604 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 602 ms
92,588 KB
testcase_16 AC 304 ms
81,652 KB
testcase_17 AC 1,296 ms
114,656 KB
testcase_18 AC 1,902 ms
178,436 KB
testcase_19 AC 1,504 ms
145,120 KB
testcase_20 AC 1,427 ms
143,740 KB
testcase_21 AC 1,471 ms
140,452 KB
testcase_22 AC 1,328 ms
135,164 KB
testcase_23 AC 326 ms
89,804 KB
testcase_24 AC 320 ms
83,324 KB
testcase_25 AC 1,448 ms
139,356 KB
testcase_26 AC 1,538 ms
149,872 KB
testcase_27 AC 1,397 ms
143,664 KB
testcase_28 AC 1,691 ms
152,104 KB
testcase_29 AC 1,334 ms
118,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

INF = float('inf')

N, M = map(int, input().split())

c = [[0] * N for _ in range(N)]
for _ in range(M):
    h, w, cc = map(int, input().split())
    c[h - 1][w - 1] = cc

dp = [[(INF, 0)] * N for _ in range(N)]
dp[0][0] = (0, 0)
q = deque([(0, 0)])
while q:
    h, w = q.popleft()
    t, m = dp[h][w]
    if h != 0:
        a, b = dp[h - 1][w]
        d = t + 1 + c[h - 1][w]
        e = max(m, c[h - 1][w])
        if d < a:
            dp[h - 1][w] = (d, e)
            q.append((h - 1, w))
    if h != N - 1:
        a, b = dp[h + 1][w]
        d = t + 1 + c[h + 1][w]
        e = max(m, c[h + 1][w])
        if d < a:
            dp[h + 1][w] = (d, e)
            q.append((h + 1, w))
    if w != 0:
        a, b = dp[h][w - 1]
        d = t + 1 + c[h][w - 1]
        e = max(m, c[h][w - 1])
        if d < a:
            dp[h][w - 1] = (d, e)
            q.append((h, w - 1))
    if w != N - 1:
        a, b = dp[h][w + 1]
        d = t + 1 + c[h][w + 1]
        e = max(m, c[h][w + 1])
        if d < a:
            dp[h][w + 1] = (d, e)
            q.append((h, w + 1))
t, m = dp[N - 1][N - 1]
print(t - m)
0