結果

問題 No.837 Noelちゃんと星々2
ユーザー 👑 jupirojupiro
提出日時 2020-02-15 20:10:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,569 bytes
コンパイル時間 1,318 ms
コンパイル使用メモリ 115,816 KB
実行使用メモリ 5,120 KB
最終ジャッジ日時 2023-09-02 07:30:18
合計ジャッジ時間 3,063 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
5,076 KB
testcase_01 AC 24 ms
4,940 KB
testcase_02 AC 24 ms
5,120 KB
testcase_03 AC 24 ms
4,932 KB
testcase_04 AC 24 ms
5,072 KB
testcase_05 AC 24 ms
4,996 KB
testcase_06 AC 24 ms
4,904 KB
testcase_07 AC 24 ms
4,992 KB
testcase_08 AC 24 ms
5,048 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,384 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 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,384 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 #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll N;
ll a[200500];
ll sum[200500];
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	scanf("%lld", &N);
	for (ll i = 0; i < N; i++) scanf("%lld", &a[i]);
	sort(a, a + N);
	if (a[0] == a[N - 1]) {
		puts("1");
		return 0;
	}
	for (ll i = 0; i < N; i++) sum[i + 1] = sum[i] + a[i];
	ll res = INF;
	for (ll i = 0; i < N - 1; i++) {
		ll lcnt = i + 1;
		ll rcnt = N - lcnt;
		ll tmp = 0;
		ll lc = lcnt / 2;
		ll rc = i + 1 + rcnt / 2;
		tmp += a[lc] * (lc + 1) - sum[lc + 1] + sum[lcnt] - sum[lc + 1] - a[lc] * (lcnt - lc - 1);
		tmp += a[rc] * (rc - i) - (sum[rc + 1] - sum[lcnt]) + sum[N] - sum[rc + 1] - a[rc] * (N - rc - 1);
		chmin(res, tmp);
	}
	cout << res << endl;
	return 0;
}
0