結果

問題 No.1077 Noelちゃんと星々4
ユーザー kurimupykurimupy
提出日時 2020-06-12 21:45:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 557 ms / 2,000 ms
コード長 688 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 273,324 KB
最終ジャッジ日時 2023-09-06 10:06:24
合計ジャッジ時間 9,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 200 ms
155,336 KB
testcase_01 AC 213 ms
155,316 KB
testcase_02 AC 424 ms
237,412 KB
testcase_03 AC 500 ms
253,352 KB
testcase_04 AC 297 ms
187,056 KB
testcase_05 AC 261 ms
167,456 KB
testcase_06 AC 304 ms
184,108 KB
testcase_07 AC 338 ms
200,876 KB
testcase_08 AC 304 ms
184,528 KB
testcase_09 AC 291 ms
185,760 KB
testcase_10 AC 496 ms
252,820 KB
testcase_11 AC 402 ms
218,652 KB
testcase_12 AC 359 ms
203,072 KB
testcase_13 AC 258 ms
167,308 KB
testcase_14 AC 491 ms
254,024 KB
testcase_15 AC 350 ms
201,972 KB
testcase_16 AC 306 ms
186,584 KB
testcase_17 AC 359 ms
203,644 KB
testcase_18 AC 490 ms
254,248 KB
testcase_19 AC 260 ms
167,052 KB
testcase_20 AC 200 ms
155,108 KB
testcase_21 AC 557 ms
273,324 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
K = list(map(int, input().split()))
# dp[N][X] = N版目まで見て条件をみたし、かつ最後の高さが[x以下]となるような物の最小コスト値
# 計算量 10**7
dp = [[10**20 for i in range(10001)] for j in range(1001)]
for i in range(10001):
    dp[1][i] = abs(i-K[0])
    if i > 0:
        dp[1][i] = min(dp[1][i], dp[1][i-1])

# 初期条件
for i in range(1, N):
    now = K[i]
    for j in range(10001):
        # 最後の高さをjとするとき
        dp[i+1][j] = dp[i][j]+abs(now-j)
        if j > 0:
            dp[i+1][j] = min(dp[i+1][j], dp[i+1][j-1])
ans = float("inf")
for i in range(10001):
    ans = min(ans, dp[N][i])
print(ans)
0