結果

問題 No.1077 Noelちゃんと星々4
ユーザー d9et
提出日時 2020-06-12 21:35:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 257 ms / 2,000 ms
コード長 295 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 154,296 KB
最終ジャッジ日時 2024-06-24 04:33:59
合計ジャッジ時間 4,137 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(int,input().split()))
mx = max(a)
dp = [[10**18 for i in range(mx+1)] for j in range(n+1)]
dp[0][0] = 0
for i in range(1,n+1):
    x = a[i-1]
    mn = 10**18
    for j in range(mx+1):
        mn = min(mn,dp[i-1][j])
        dp[i][j] = mn+abs(x-j)
print(min(dp[-1]))
0