結果

問題 No.837 Noelちゃんと星々2
ユーザー ransewhaleransewhale
提出日時 2019-06-14 21:49:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 928 bytes
コンパイル時間 1,691 ms
コンパイル使用メモリ 168,804 KB
実行使用メモリ 5,112 KB
最終ジャッジ日時 2023-09-02 07:20:09
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
4,908 KB
testcase_01 AC 50 ms
4,972 KB
testcase_02 AC 50 ms
5,112 KB
testcase_03 AC 49 ms
4,904 KB
testcase_04 AC 50 ms
5,104 KB
testcase_05 AC 49 ms
4,916 KB
testcase_06 AC 50 ms
4,972 KB
testcase_07 AC 50 ms
4,964 KB
testcase_08 AC 50 ms
4,916 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[100100],s[100100];

ll f(int l, int r){
	int p;
	ll ret = 0ll;
	if(r-l==0){
		return 0ll;
	}else if(r-l==1){
		return (a[r-1]-a[l-1]);
	}
	p = (l+r)/2;
	if(((r-l)%2)){
		ret += (s[r]-s[p]);
		ret -= (s[p]-s[l-1]);
	}else{
		ret += (s[r]-s[p]);
		ret -= (s[p-1]-s[l-1]);
	}
	return ret;
}

int main(void){
	int n,i,p;
	ll ans=INFLL;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
	}
	sort(a,a+n);
	if(a[0]==a[n-1]){
		cout << 1 << endl;
		return 0;
	}
	for(i=0; i<n; ++i){
		s[i+1] = a[i]+s[i];
	}
	for(i=1; i<n; ++i){
		ans = min(ans,f(1,i)+f(i+1,n));
	}
	cout << ans << endl;
	return 0;
}
0