結果

問題 No.838 Noelちゃんと星々3
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-11-01 15:12:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 396 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 18,988 KB
最終ジャッジ日時 2023-10-13 00:48:32
合計ジャッジ時間 3,335 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 16 ms
7,808 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 15 ms
8,140 KB
testcase_17 AC 15 ms
8,228 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 16 ms
7,916 KB
testcase_21 AC 16 ms
7,820 KB
testcase_22 AC 16 ms
7,796 KB
testcase_23 AC 16 ms
7,780 KB
testcase_24 AC 16 ms
7,776 KB
testcase_25 AC 15 ms
7,900 KB
testcase_26 AC 15 ms
7,796 KB
testcase_27 AC 16 ms
8,196 KB
testcase_28 AC 16 ms
7,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if N <= 3:
    print(Y[-1] - Y[0])
    exit()

INF = float('inf')
dp = [0] * N
dp[0] = INF
dp[1] = Y[1] - Y[0]
dp[2] = Y[2] - Y[0]

for i, y in enumerate(Y[3:], start=3):
    d2 = dp[i - 3] + (y - Y[i - 2])  # xxx o o o
    d3 = dp[i - 4] + (y - Y[i - 1]) + (Y[i - 2] - Y[i - 3])  # xxx o o o o
    dp[i] = min(d2, d3)

print(dp[-1])
0