結果

問題 No.1077 Noelちゃんと星々4
ユーザー ああいいああいい
提出日時 2022-02-23 14:42:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 371 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 87,220 KB
実行使用メモリ 155,172 KB
最終ジャッジ日時 2023-09-14 06:54:35
合計ジャッジ時間 5,544 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
75,984 KB
testcase_01 AC 78 ms
76,036 KB
testcase_02 AC 225 ms
130,524 KB
testcase_03 AC 260 ms
138,504 KB
testcase_04 AC 135 ms
92,752 KB
testcase_05 AC 125 ms
92,204 KB
testcase_06 AC 147 ms
92,648 KB
testcase_07 AC 173 ms
108,052 KB
testcase_08 AC 137 ms
92,784 KB
testcase_09 AC 137 ms
92,800 KB
testcase_10 AC 253 ms
138,664 KB
testcase_11 AC 190 ms
115,584 KB
testcase_12 AC 177 ms
113,748 KB
testcase_13 AC 122 ms
91,224 KB
testcase_14 AC 252 ms
138,624 KB
testcase_15 AC 175 ms
112,700 KB
testcase_16 AC 135 ms
92,848 KB
testcase_17 AC 183 ms
115,848 KB
testcase_18 AC 255 ms
138,560 KB
testcase_19 AC 123 ms
90,536 KB
testcase_20 AC 70 ms
71,316 KB
testcase_21 AC 287 ms
155,172 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
Y = list(map(int,input().split()))
import sys
if N == 1:
    print(0)
    exit()

C = 10 ** 4
inf = 10 ** 10
dp = [[inf] * (C+1) for _ in range(N)]
for i in range(C+1):
    dp[0][i] = abs(i-Y[0])
for i in range(N-1):
    _min = inf
    for j in range(C+1):
        _min = min(_min,dp[i][j])
        dp[i+1][j] = _min + abs(j - Y[i+1])
print(min(dp[-1]))
0