結果

問題 No.837 Noelちゃんと星々2
ユーザー hirokazu1020hirokazu1020
提出日時 2019-06-14 21:55:28
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,221 bytes
コンパイル時間 1,472 ms
コンパイル使用メモリ 98,940 KB
実行使用メモリ 4,800 KB
最終ジャッジ日時 2023-09-02 07:20:13
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
4,572 KB
testcase_01 AC 24 ms
4,580 KB
testcase_02 AC 23 ms
4,564 KB
testcase_03 AC 24 ms
4,696 KB
testcase_04 AC 23 ms
4,676 KB
testcase_05 AC 24 ms
4,676 KB
testcase_06 AC 23 ms
4,800 KB
testcase_07 AC 24 ms
4,624 KB
testcase_08 AC 23 ms
4,688 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,500 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int n;
	cin >> n;
	vector<long long> y(n);
	rep(i, n)cin >> y[i];
	sort(all(y));

	if (y.front() == y.back()) {
		cout << 1 << endl;
		return 0;
	}

	vector<long long> s(n, 0);
	s[0] = y[0];
	rep(i, n - 1) {
		s[i + 1] = s[i] + y[i + 1];
	}



	long long ans = 1LL << 60;
	rep(i, n - 1) {
		int m1 = (0 + i) / 2;
		int m2 = (i + 1 + n - 1) / 2;

		auto a = s[i] - s[m1] - y[m1] * (i - m1) + y[m1] * (m1 + 1) - (s[m1]);
		auto b = s[n - 1] - s[m2] - y[m2] * (n - 1 - m2) + y[m2] * (m2 - i) - (s[m2] - s[i]);

		ans = min(ans, a + b);
	}
	cout << ans << endl;


	return 0;
}
0