結果

問題 No.1077 Noelちゃんと星々4
ユーザー ttrttr
提出日時 2020-06-12 21:52:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 304 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 86,596 KB
実行使用メモリ 155,228 KB
最終ジャッジ日時 2023-09-06 10:16:58
合計ジャッジ時間 5,387 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,192 KB
testcase_01 AC 63 ms
71,272 KB
testcase_02 AC 227 ms
130,552 KB
testcase_03 AC 232 ms
138,604 KB
testcase_04 AC 132 ms
92,492 KB
testcase_05 AC 120 ms
91,768 KB
testcase_06 AC 146 ms
104,044 KB
testcase_07 AC 153 ms
107,948 KB
testcase_08 AC 135 ms
92,692 KB
testcase_09 AC 124 ms
92,524 KB
testcase_10 AC 244 ms
138,400 KB
testcase_11 AC 185 ms
115,668 KB
testcase_12 AC 169 ms
113,404 KB
testcase_13 AC 122 ms
91,228 KB
testcase_14 AC 249 ms
138,368 KB
testcase_15 AC 176 ms
112,512 KB
testcase_16 AC 126 ms
92,824 KB
testcase_17 AC 173 ms
115,528 KB
testcase_18 AC 250 ms
138,408 KB
testcase_19 AC 120 ms
90,820 KB
testcase_20 AC 66 ms
75,656 KB
testcase_21 AC 271 ms
155,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
Y = [int(y) for y in input().split()]

M = max(Y)
dp = [[0]*(M+1) for _ in range(N)]

for j in range(M+1):
    dp[0][j] = abs(j-Y[0])

for i in range(1, N):
    m = dp[i-1][0]
    for j in range(M+1):
        m = min(m, dp[i-1][j])
        dp[i][j] = m + abs(Y[i]-j)

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