結果

問題 No.838 Noelちゃんと星々3
ユーザー ahe100ahe100
提出日時 2019-06-14 23:07:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 1,467 ms
コンパイル使用メモリ 166,848 KB
実行使用メモリ 5,092 KB
最終ジャッジ日時 2023-08-09 07:00:49
合計ジャッジ時間 3,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
5,084 KB
testcase_01 AC 47 ms
4,912 KB
testcase_02 AC 47 ms
4,948 KB
testcase_03 AC 46 ms
4,948 KB
testcase_04 AC 48 ms
5,092 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
適切にペアを作る
3つ一致する場合も考える。
*/

ll n,a[100010],dp[100010],ans=1e18;

void init(){
	cin>>n;
	a[0]=-1e18;
	reg(i,1,n)cin>>a[i];
	sort(a+1,a+n+1);
	rep(i,n+1)dp[i]=1e18;
	dp[0]=0;
	dp[1]=1e18;
}

int main(void){
	init();
	reg(i,2,n){
		dp[i]=abs(a[i]-a[i-1])+dp[i-2];
		if(i>=3)dp[i]=min(dp[i],abs(a[i]-a[i-1])+abs(a[i-1]-a[i-2])+dp[i-3]);
	}
	cout<<dp[n]<<endl;
	return 0;
}
0