結果

問題 No.1077 Noelちゃんと星々4
ユーザー AEnAEn
提出日時 2022-08-23 16:02:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 411 ms / 2,000 ms
コード長 333 bytes
コンパイル時間 204 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 230,080 KB
最終ジャッジ日時 2024-04-19 07:36:23
合計ジャッジ時間 5,936 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
61,568 KB
testcase_01 AC 49 ms
64,000 KB
testcase_02 AC 325 ms
177,304 KB
testcase_03 AC 364 ms
206,048 KB
testcase_04 AC 150 ms
109,312 KB
testcase_05 AC 140 ms
107,136 KB
testcase_06 AC 187 ms
123,240 KB
testcase_07 AC 208 ms
136,960 KB
testcase_08 AC 171 ms
120,668 KB
testcase_09 AC 146 ms
109,056 KB
testcase_10 AC 362 ms
206,236 KB
testcase_11 AC 274 ms
161,864 KB
testcase_12 AC 238 ms
147,200 KB
testcase_13 AC 124 ms
96,384 KB
testcase_14 AC 370 ms
204,400 KB
testcase_15 AC 234 ms
147,160 KB
testcase_16 AC 167 ms
121,600 KB
testcase_17 AC 239 ms
149,356 KB
testcase_18 AC 407 ms
215,744 KB
testcase_19 AC 130 ms
96,256 KB
testcase_20 AC 42 ms
59,520 KB
testcase_21 AC 411 ms
230,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
Y = list(map(int, input().split()))

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