結果

問題 No.1077 Noelちゃんと星々4
ユーザー c-yanc-yan
提出日時 2020-06-14 09:13:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 336 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 84,708 KB
最終ジャッジ日時 2023-09-09 07:12:11
合計ジャッジ時間 3,354 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,208 KB
testcase_01 AC 71 ms
71,116 KB
testcase_02 AC 102 ms
80,748 KB
testcase_03 AC 108 ms
83,252 KB
testcase_04 AC 90 ms
76,632 KB
testcase_05 AC 85 ms
76,196 KB
testcase_06 AC 90 ms
76,392 KB
testcase_07 AC 88 ms
76,392 KB
testcase_08 AC 88 ms
76,340 KB
testcase_09 AC 89 ms
76,672 KB
testcase_10 AC 108 ms
83,304 KB
testcase_11 AC 96 ms
76,756 KB
testcase_12 AC 92 ms
76,696 KB
testcase_13 AC 85 ms
76,128 KB
testcase_14 AC 107 ms
82,824 KB
testcase_15 AC 90 ms
76,608 KB
testcase_16 AC 87 ms
76,724 KB
testcase_17 AC 93 ms
76,876 KB
testcase_18 AC 107 ms
83,692 KB
testcase_19 AC 85 ms
76,164 KB
testcase_20 AC 72 ms
71,388 KB
testcase_21 AC 110 ms
84,708 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