結果

問題 No.1283 Extra Fee
ユーザー c-yanc-yan
提出日時 2020-11-06 23:16:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,142 bytes
コンパイル時間 413 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 172,788 KB
最終ジャッジ日時 2023-09-29 19:35:11
合計ジャッジ時間 20,633 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,676 KB
testcase_01 AC 90 ms
71,820 KB
testcase_02 AC 89 ms
71,808 KB
testcase_03 AC 89 ms
71,736 KB
testcase_04 AC 90 ms
71,732 KB
testcase_05 AC 90 ms
71,600 KB
testcase_06 WA -
testcase_07 AC 91 ms
71,700 KB
testcase_08 AC 91 ms
71,828 KB
testcase_09 WA -
testcase_10 AC 90 ms
71,392 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 515 ms
91,852 KB
testcase_16 AC 273 ms
82,188 KB
testcase_17 AC 1,022 ms
110,024 KB
testcase_18 AC 1,695 ms
172,788 KB
testcase_19 AC 1,366 ms
140,496 KB
testcase_20 AC 1,248 ms
138,816 KB
testcase_21 AC 1,206 ms
135,156 KB
testcase_22 AC 1,135 ms
131,568 KB
testcase_23 AC 315 ms
89,692 KB
testcase_24 AC 314 ms
83,340 KB
testcase_25 AC 1,285 ms
136,852 KB
testcase_26 AC 1,384 ms
146,892 KB
testcase_27 AC 1,198 ms
138,748 KB
testcase_28 AC 1,464 ms
146,800 KB
testcase_29 AC 1,055 ms
113,316 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

INF = 10 ** 18

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