結果

問題 No.1077 Noelちゃんと星々4
ユーザー neurousneurous
提出日時 2020-06-13 01:38:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 280 ms / 2,000 ms
コード長 376 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 155,520 KB
最終ジャッジ日時 2023-09-06 11:39:04
合計ジャッジ時間 5,113 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
71,544 KB
testcase_01 AC 64 ms
71,548 KB
testcase_02 AC 229 ms
130,808 KB
testcase_03 AC 265 ms
136,036 KB
testcase_04 AC 135 ms
91,316 KB
testcase_05 AC 118 ms
90,864 KB
testcase_06 AC 147 ms
91,312 KB
testcase_07 AC 176 ms
108,196 KB
testcase_08 AC 134 ms
91,332 KB
testcase_09 AC 131 ms
91,644 KB
testcase_10 AC 257 ms
135,832 KB
testcase_11 AC 191 ms
113,576 KB
testcase_12 AC 181 ms
113,752 KB
testcase_13 AC 124 ms
91,260 KB
testcase_14 AC 260 ms
136,208 KB
testcase_15 AC 178 ms
112,740 KB
testcase_16 AC 130 ms
91,400 KB
testcase_17 AC 188 ms
113,940 KB
testcase_18 AC 267 ms
135,948 KB
testcase_19 AC 114 ms
90,964 KB
testcase_20 AC 69 ms
76,196 KB
testcase_21 AC 280 ms
155,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
a = list(map(int, input().split()))
mn = min(a)
for i in a:
    i -= mn
mx = max(a)
dp = [[0 for _ in range(mx+1)] for __ in range(N)]
for i in range(mx+1):
    dp[0][i] = abs(a[0]-i)

for i in range(1, N):
    mn = dp[i-1][0]
    for j in range(mx+1):
        mn = dp[i-1][j] if dp[i-1][j] < mn else mn
        dp[i][j] = mn + abs(a[i]-j)

print(min(dp[-1]))
0