結果

問題 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
コンパイル時間 247 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 367,328 KB
最終ジャッジ日時 2023-09-06 10:48:56
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
355,744 KB
testcase_01 AC 46 ms
12,096 KB
testcase_02 TLE -
testcase_03 TLE -
testcase_04 AC 840 ms
112,480 KB
testcase_05 AC 636 ms
86,320 KB
testcase_06 AC 1,093 ms
143,852 KB
testcase_07 AC 1,293 ms
164,944 KB
testcase_08 AC 910 ms
121,780 KB
testcase_09 AC 820 ms
105,852 KB
testcase_10 TLE -
testcase_11 AC 1,877 ms
233,028 KB
testcase_12 AC 1,504 ms
193,196 KB
testcase_13 AC 611 ms
82,336 KB
testcase_14 TLE -
testcase_15 AC 1,440 ms
186,868 KB
testcase_16 AC 967 ms
124,940 KB
testcase_17 AC 1,701 ms
210,988 KB
testcase_18 TLE -
testcase_19 AC 565 ms
78,776 KB
testcase_20 AC 17 ms
8,628 KB
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

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