結果

問題 No.838 Noelちゃんと星々3
ユーザー dama_mathdama_math
提出日時 2019-06-14 19:54:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 897 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 166,420 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-25 23:04:14
合計ジャッジ時間 3,359 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define ROF(i,a,b) for(int i=b-1;i>=a;--i)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const ll LINF=1e18;
const int MOD=1e9+7;
//const int MOD=998244353;

ll y[100000],dp[100000];

int main(){
	int n; cin>>n;
	assert(n>=2 && n<=100000);
	FOR(i,0,n){
		cin>>y[i];
		assert(-1e9<=y[i] && y[i]<=1e9);
	}
	sort(y,y+n);
	dp[0]=LINF;
	dp[1]=y[1]-y[0];
	dp[2]=y[2]-y[0];
	FOR(i,3,n){
		dp[i]=min(dp[i-3]+y[i]-y[i-2],dp[i-2]+y[i]-y[i-1]);
	}
	co(dp[n-1]);
}
0