結果

問題 No.1077 Noelちゃんと星々4
ユーザー TsuboTsubo
提出日時 2020-06-12 22:39:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 694 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 277,664 KB
最終ジャッジ日時 2024-06-24 05:24:25
合計ジャッジ時間 3,863 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,000 KB
testcase_01 AC 74 ms
14,464 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
def main():
    #入力
    readline=stdin.readline
    n=int(readline())
    y=list(map(int,readline().split()))

    dp=[[0]*(10**4+1) for _ in range(n)]
    for i in range(n):
        y_now=y[i]
        if i==0:
            for j in range(10**4+1):
                dp[i][j]=abs(y_now-j)
        else:
            for j in range(10**4+1):
                if j==0:
                    before_min=dp[i-1][j]
                else:
                    before_min=min(before_min,dp[i-1][j])
                dp[i][j]=before_min+abs(y_now-j)

    ans=float("inf")
    for j in range(10**4+1):
        ans=min(ans,dp[n-1][j])

    print(ans)

if __name__=="__main__":
    main()
0