結果

問題 No.838 Noelちゃんと星々3
ユーザー convexineqconvexineq
提出日時 2021-04-03 13:56:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 222 bytes
コンパイル時間 1,027 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 95,232 KB
最終ジャッジ日時 2023-08-26 04:44:12
合計ジャッジ時間 5,155 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
95,168 KB
testcase_01 AC 122 ms
94,952 KB
testcase_02 AC 121 ms
95,136 KB
testcase_03 AC 121 ms
95,152 KB
testcase_04 AC 123 ms
95,232 KB
testcase_05 AC 73 ms
71,204 KB
testcase_06 AC 75 ms
71,276 KB
testcase_07 AC 73 ms
71,456 KB
testcase_08 AC 73 ms
71,316 KB
testcase_09 AC 73 ms
71,552 KB
testcase_10 AC 73 ms
71,340 KB
testcase_11 AC 71 ms
71,076 KB
testcase_12 AC 73 ms
71,460 KB
testcase_13 AC 73 ms
71,272 KB
testcase_14 AC 74 ms
71,320 KB
testcase_15 AC 76 ms
71,312 KB
testcase_16 AC 79 ms
71,232 KB
testcase_17 AC 73 ms
71,364 KB
testcase_18 AC 73 ms
71,172 KB
testcase_19 AC 74 ms
71,268 KB
testcase_20 AC 73 ms
71,348 KB
testcase_21 AC 75 ms
71,204 KB
testcase_22 AC 76 ms
71,328 KB
testcase_23 AC 75 ms
71,028 KB
testcase_24 AC 74 ms
71,284 KB
testcase_25 AC 74 ms
71,208 KB
testcase_26 AC 74 ms
71,280 KB
testcase_27 AC 73 ms
71,040 KB
testcase_28 AC 75 ms
71,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
*a, = map(int,input().split())
a.sort()
INF = 10**18
dp = [INF]*n
dp[1] = a[1] - a[0]
for i in range(2,n):
    dp[i] = min(dp[i-2] + a[i] - a[i-1], (dp[i-3] if i >= 3 else 0) + a[i] - a[i-2])
print(dp[-1])
0