結果

問題 No.838 Noelちゃんと星々3
ユーザー okok
提出日時 2019-06-15 01:16:13
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 622 ms
コンパイル使用メモリ 74,916 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-27 15:54:45
合計ジャッジ時間 1,533 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = (long long)1e9 + 7; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}

#define MAX 110000

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N;
	static int Y[MAX], dp[MAX];
	
	cin>>N;
	
	for(int i = 0; i < N; i++){
		cin>>Y[i];
	}
	
	sort(Y, Y + N);
	
	dp[1] = INF;
	dp[2] = dp[1] + Y[1] - Y[0];
	
	for(int i = 2; i < N; i++){
		dp[i+1] = dp[i-1] + Y[i] - Y[i-1];
		dp[i+1] = min(dp[i+1], dp[i-2] + Y[i] - Y[i-1] + Y[i-1] - Y[i-2]);
	}
	
	cout<<dp[N]<<endl;
	
	return 0;
}
0