結果

問題 No.1077 Noelちゃんと星々4
ユーザー TsuboTsubo
提出日時 2020-06-12 22:39:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 86,804 KB
実行使用メモリ 154,924 KB
最終ジャッジ日時 2023-09-06 10:50:57
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
75,548 KB
testcase_01 AC 77 ms
75,660 KB
testcase_02 AC 203 ms
129,756 KB
testcase_03 AC 234 ms
145,860 KB
testcase_04 AC 127 ms
97,388 KB
testcase_05 AC 109 ms
91,744 KB
testcase_06 AC 142 ms
103,528 KB
testcase_07 AC 158 ms
108,032 KB
testcase_08 AC 131 ms
98,972 KB
testcase_09 AC 121 ms
95,980 KB
testcase_10 AC 235 ms
146,036 KB
testcase_11 AC 185 ms
121,060 KB
testcase_12 AC 166 ms
113,500 KB
testcase_13 AC 114 ms
90,840 KB
testcase_14 AC 234 ms
144,932 KB
testcase_15 AC 169 ms
112,252 KB
testcase_16 AC 133 ms
99,676 KB
testcase_17 AC 173 ms
117,000 KB
testcase_18 AC 235 ms
147,412 KB
testcase_19 AC 108 ms
90,584 KB
testcase_20 AC 68 ms
75,516 KB
testcase_21 AC 248 ms
154,924 KB
権限があれば一括ダウンロードができます

ソースコード

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