結果

問題 No.1077 Noelちゃんと星々4
ユーザー c-yanc-yan
提出日時 2020-06-14 09:12:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 336 bytes
コンパイル時間 262 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 45,400 KB
最終ジャッジ日時 2023-09-09 07:10:37
合計ジャッジ時間 6,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,824 KB
testcase_01 AC 16 ms
7,936 KB
testcase_02 AC 349 ms
25,864 KB
testcase_03 AC 564 ms
37,804 KB
testcase_04 AC 67 ms
10,952 KB
testcase_05 AC 43 ms
9,596 KB
testcase_06 AC 102 ms
12,924 KB
testcase_07 AC 131 ms
14,460 KB
testcase_08 AC 77 ms
11,484 KB
testcase_09 AC 62 ms
10,488 KB
testcase_10 AC 580 ms
38,348 KB
testcase_11 AC 249 ms
20,912 KB
testcase_12 AC 180 ms
16,760 KB
testcase_13 AC 42 ms
9,580 KB
testcase_14 AC 552 ms
36,124 KB
testcase_15 AC 167 ms
16,296 KB
testcase_16 AC 78 ms
11,484 KB
testcase_17 AC 209 ms
18,360 KB
testcase_18 AC 586 ms
39,216 KB
testcase_19 AC 39 ms
9,356 KB
testcase_20 AC 16 ms
7,820 KB
testcase_21 AC 735 ms
45,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
Y = list(map(int, input().split()))

a = sorted(set(Y))
dp = [[0] * len(a) for _ in range(N)]

for i in range(len(a)):
    dp[0][i] = abs(Y[0] - a[i])

for i in range(1, N):
    t = float('inf')
    for j in range(len(a)):
        t = min(t, dp[i - 1][j])
        dp[i][j] = t + abs(Y[i] - a[j])

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