結果

問題 No.1077 Noelちゃんと星々4
ユーザー c-yanc-yan
提出日時 2020-06-14 09:08:51
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 338 bytes
コンパイル時間 834 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 92,484 KB
最終ジャッジ日時 2023-09-09 07:09:11
合計ジャッジ時間 13,842 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
70,780 KB
testcase_01 AC 79 ms
71,060 KB
testcase_02 AC 786 ms
83,860 KB
testcase_03 AC 1,446 ms
88,748 KB
testcase_04 AC 135 ms
77,788 KB
testcase_05 AC 105 ms
76,952 KB
testcase_06 AC 183 ms
78,628 KB
testcase_07 AC 400 ms
78,892 KB
testcase_08 AC 146 ms
77,620 KB
testcase_09 AC 124 ms
77,500 KB
testcase_10 AC 1,481 ms
88,924 KB
testcase_11 AC 472 ms
81,652 KB
testcase_12 AC 309 ms
80,056 KB
testcase_13 AC 121 ms
76,856 KB
testcase_14 AC 1,344 ms
88,168 KB
testcase_15 AC 297 ms
80,144 KB
testcase_16 AC 147 ms
77,568 KB
testcase_17 AC 377 ms
80,748 KB
testcase_18 AC 1,543 ms
89,236 KB
testcase_19 AC 103 ms
76,852 KB
testcase_20 AC 76 ms
70,920 KB
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

INF = float('inf')

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

a = sorted(set(Y))
maxY = max(Y)

dp = [[INF] * 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):
    for j in range(len(a)):
        dp[i][j] = min(dp[i - 1][:j+1]) + abs(Y[i] - a[j])

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