結果

問題 No.838 Noelちゃんと星々3
ユーザー stngstng
提出日時 2022-07-16 13:09:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 439 bytes
コンパイル時間 1,663 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 111,688 KB
最終ジャッジ日時 2023-09-10 21:32:01
合計ジャッジ時間 5,412 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 233 ms
111,688 KB
testcase_01 AC 234 ms
111,404 KB
testcase_02 AC 231 ms
111,436 KB
testcase_03 AC 227 ms
111,440 KB
testcase_04 AC 228 ms
111,652 KB
testcase_05 AC 72 ms
71,272 KB
testcase_06 AC 73 ms
71,268 KB
testcase_07 AC 72 ms
71,280 KB
testcase_08 AC 74 ms
71,288 KB
testcase_09 AC 76 ms
71,384 KB
testcase_10 AC 73 ms
71,212 KB
testcase_11 AC 75 ms
71,492 KB
testcase_12 AC 72 ms
71,304 KB
testcase_13 AC 73 ms
71,320 KB
testcase_14 AC 72 ms
71,428 KB
testcase_15 AC 73 ms
71,320 KB
testcase_16 AC 72 ms
71,392 KB
testcase_17 AC 72 ms
71,384 KB
testcase_18 AC 73 ms
71,112 KB
testcase_19 AC 72 ms
71,252 KB
testcase_20 AC 73 ms
71,384 KB
testcase_21 AC 75 ms
71,396 KB
testcase_22 AC 72 ms
71,048 KB
testcase_23 AC 74 ms
71,200 KB
testcase_24 AC 72 ms
71,396 KB
testcase_25 AC 74 ms
71,312 KB
testcase_26 AC 74 ms
71,376 KB
testcase_27 AC 74 ms
71,124 KB
testcase_28 AC 72 ms
71,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
y = [int(i) for i in input().split()]

y.sort()
dp = [[[10**15]*2 for _ in range(3)] for _ in range(n)]

dp[0][1][0] = 0
dp[0][2][0] = y[1]-y[0]

for i in range(1,n):
    dp[i][0][1] = min(dp[i-1][1])+y[i]-y[i-1]
    dp[i][1][0] = min(dp[i-1][1][1],dp[i-1][0][1])
    dp[i][1][1] = min(dp[i-1][2])
    if i != n-1:
        dp[i][2][0] = min(dp[i-1][1][1],dp[i-1][0][1])+y[i+1]-y[i]

print(min(dp[n-1][0][1],dp[n-1][1][1]))
0