結果

問題 No.1283 Extra Fee
ユーザー rlangevinrlangevin
提出日時 2023-02-05 22:34:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 852 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 84,364 KB
最終ジャッジ日時 2023-09-17 12:21:30
合計ジャッジ時間 8,422 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,384 KB
testcase_01 AC 72 ms
71,396 KB
testcase_02 AC 75 ms
71,392 KB
testcase_03 AC 72 ms
71,288 KB
testcase_04 AC 73 ms
71,476 KB
testcase_05 AC 71 ms
71,316 KB
testcase_06 AC 72 ms
71,116 KB
testcase_07 AC 71 ms
71,168 KB
testcase_08 AC 72 ms
71,296 KB
testcase_09 AC 73 ms
71,448 KB
testcase_10 AC 73 ms
71,592 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 101 ms
77,708 KB
testcase_17 AC 155 ms
83,688 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 188 ms
83,412 KB
testcase_24 AC 195 ms
83,320 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 155 ms
84,364 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

N, M = map(int, readline().split())
inf = 10 ** 18
dp0 = [[inf] * N for i in range(N)]
dp1 = [[inf] * N for i in range(N)]
cost = [[0] * N for i in range(N)]
dp0[0][0] = 0

for i in range(M):
    h, w, c = map(int, readline().split())
    h, w = h - 1, w - 1
    cost[h][w] = c
    
for i in range(N):
    for j in range(N):
        if i - 1 >= 0:
            dp0[i][j] = min(dp0[i][j], dp0[i - 1][j] + cost[i][j])
            dp1[i][j] = min(dp1[i][j], dp1[i - 1][j] + cost[i][j])
            dp1[i][j] = min(dp1[i][j], dp0[i - 1][j])
        if j - 1 >= 0:
            dp0[i][j] = min(dp0[i][j], dp0[i][j - 1] + cost[i][j])
            dp1[i][j] = min(dp1[i][j], dp1[i][j - 1] + cost[i][j])
            dp1[i][j] = min(dp1[i][j], dp0[i][j - 1])
            
print(min(dp0[-1][-1], dp1[-1][-1]) + 2 * (N - 1))
0