結果

問題 No.837 Noelちゃんと星々2
ユーザー leaf_1415leaf_1415
提出日時 2019-06-14 21:34:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 2,183 ms
コンパイル使用メモリ 62,156 KB
実行使用メモリ 5,108 KB
最終ジャッジ日時 2023-09-02 07:18:01
合計ジャッジ時間 2,907 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint n;
llint x[100005], sum[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i];
	sort(x+1, x+n+1);
	for(int i = 1; i <= n; i++) sum[i] = sum[i-1] + x[i];
	
	if(x[1] == x[n]){
		cout << 1 << endl;
		return 0;
	}
	
	llint ans = 1e18;
	for(int i = 0; i <= n; i++){
		llint m1 = (1+i)/2, m2 = (i+1+n)/2;
		llint tmp = m1*x[m1] - sum[m1] + (sum[i]-sum[m1]) - (i-m1)*x[m1];
		tmp += (m2-i)*x[m2] - (sum[m2]-sum[i]) + (sum[n]-sum[m2]) - (n-m2)*x[m2];
		ans = min(ans, tmp);
	}
	cout << ans << endl;
	
	return 0;
}
0