結果

問題 No.837 Noelちゃんと星々2
ユーザー yuruhiyayuruhiya
提出日時 2020-03-05 18:52:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 15 ms / 2,000 ms
コード長 1,409 bytes
コンパイル時間 534 ms
コンパイル使用メモリ 50,892 KB
実行使用メモリ 4,556 KB
最終ジャッジ日時 2023-09-02 07:30:27
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,404 KB
testcase_01 AC 15 ms
4,544 KB
testcase_02 AC 15 ms
4,472 KB
testcase_03 AC 15 ms
4,556 KB
testcase_04 AC 15 ms
4,404 KB
testcase_05 AC 15 ms
4,548 KB
testcase_06 AC 15 ms
4,524 KB
testcase_07 AC 15 ms
4,532 KB
testcase_08 AC 15 ms
4,404 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 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 2 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize ("Ofast")
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)

//#define LOCAL
#ifdef LOCAL
#define gc _getchar_nolock
#include "dump.hpp"
#else
#define gc getchar_unlocked
#define dump(...) ((void)0)
#endif

inline void input(int& v)noexcept {
	v = 0; char c = gc();
	bool f = false;
	if (c == '-') { f = true; c = gc(); }
	for (; isdigit(c); c = gc()) {
		v *= 10;
		v += c - '0';
	}
	if (f)v = -v;
}
inline void input_l(long long& v)noexcept {
	v = 0; char c = gc();
	bool f = false;
	if (c == '-') {f = true; c = gc();}
	for (; isdigit(c); c = gc()) {
		v *= 10;
		v += c - '0';
	}
	if (f)v = -v;
}

int n;
long long a[100001], s[100002];

int main() {
	input(n);
	rep(i, n)input_l(a[i]);
	sort(a, a + n);

	if (a[0] == a[n - 1]) {
		puts("1");
		return 0;
	}

	rep(i, n)s[i + 1] = s[i] + a[i];

	long long ans = 1e16;
	int l = -1, r = n / 2;
	if (!(n & 1))--r;
	FOR(i, 1, n) { // [0, i) + [i, n)
		if (i & 1)++l;
		if ((n - i) & 1)++r;
		long long val = 0;
		val += a[l] * l - s[l];
		val += (s[i] - s[l + 1]) - a[l] * (i - l - 1);
		if (val >= ans)break;
		val += a[r] * (r - i) - (s[r] - s[i]);
		val += (s[n] - s[r + 1]) - a[r] * (n - r - 1);
		if (ans > val)ans = val;
	}
	printf("%lld\n", ans);
}
0