結果

問題 No.1283 Extra Fee
ユーザー c-yanc-yan
提出日時 2020-11-06 23:10:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,178 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 180,720 KB
最終ジャッジ日時 2023-09-29 19:30:31
合計ジャッジ時間 20,943 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,476 KB
testcase_01 AC 84 ms
71,400 KB
testcase_02 AC 83 ms
71,344 KB
testcase_03 AC 86 ms
71,808 KB
testcase_04 AC 90 ms
71,640 KB
testcase_05 AC 88 ms
71,644 KB
testcase_06 AC 88 ms
71,856 KB
testcase_07 AC 85 ms
71,556 KB
testcase_08 WA -
testcase_09 AC 86 ms
71,380 KB
testcase_10 AC 85 ms
71,676 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 258 ms
81,692 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 271 ms
82,288 KB
testcase_17 AC 777 ms
107,192 KB
testcase_18 AC 1,863 ms
180,720 KB
testcase_19 AC 1,435 ms
146,332 KB
testcase_20 WA -
testcase_21 AC 1,338 ms
143,512 KB
testcase_22 AC 1,251 ms
134,828 KB
testcase_23 AC 312 ms
89,784 KB
testcase_24 AC 315 ms
83,476 KB
testcase_25 WA -
testcase_26 AC 1,481 ms
153,328 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 775 ms
112,472 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 - e < a - b:
            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 - e < a - b:
            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 - e < a - b:
            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 - e < a - b:
            dp[h][w + 1] = (d, e)
            q.append((h, w + 1))
t, m = dp[N - 1][N - 1]
print(t - m)
0