結果

問題 No.837 Noelちゃんと星々2
ユーザー aa
提出日時 2019-06-14 22:25:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 801 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 174,820 KB
実行使用メモリ 9,580 KB
最終ジャッジ日時 2023-09-02 07:21:05
合計ジャッジ時間 3,982 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
9,372 KB
testcase_01 AC 90 ms
9,400 KB
testcase_02 AC 93 ms
9,340 KB
testcase_03 AC 92 ms
9,492 KB
testcase_04 AC 95 ms
9,580 KB
testcase_05 AC 91 ms
9,372 KB
testcase_06 AC 92 ms
9,376 KB
testcase_07 AC 92 ms
9,312 KB
testcase_08 AC 91 ms
9,328 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 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 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,380 KB
testcase_28 AC 1 ms
4,384 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	set<long> s;
	vector<long> ys(n), acc(n + 1);
	for (int i = 0; i < n; i++)
	{
		cin >> ys[i];
		s.insert(ys[i]);
	}
	if (s.size() == 1)
	{
		cout << 1 << endl;
		return;
	}
	sort(ys.begin(), ys.end());
	for (int i = 0; i < n; i++)
	{
		acc[i + 1] = acc[i] + ys[i];
	}
	long ans = LONG_MAX;
	for (int l = 0; l < n; l++)
	{
		int ml = l / 2, mr = (n+l)/2;
		long sl = ys[ml] * ml - acc[ml] + (acc[l] - acc[ml]) - ys[ml] * (l - ml);
		long sr = ys[mr] * (mr - l) - (acc[mr] - acc[l]) + (acc[n] - acc[mr]) - ys[mr] * (n - mr);
		//cout << ml << ' ' << sl << ' ' << mr << ' ' << sr << endl;
		ans = min(ans, sl + sr);
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0