結果

問題 No.837 Noelちゃんと星々2
ユーザー 夜
提出日時 2021-03-02 20:11:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 984 ms
コンパイル使用メモリ 100,288 KB
実行使用メモリ 11,476 KB
最終ジャッジ日時 2023-09-02 07:32:53
合計ジャッジ時間 3,503 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
11,240 KB
testcase_01 AC 91 ms
11,168 KB
testcase_02 AC 97 ms
11,360 KB
testcase_03 AC 96 ms
11,188 KB
testcase_04 AC 95 ms
11,212 KB
testcase_05 AC 93 ms
11,304 KB
testcase_06 AC 94 ms
11,236 KB
testcase_07 AC 92 ms
11,476 KB
testcase_08 AC 92 ms
11,180 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 1 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long y[100010], y2[100010];
long long l[100010] = {}, r[100010] = {};
set<long long> st;
int main(){
	long long n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> y[i];
		st.insert(y[i]);
	}
	if (st.size() == 1) {
		cout << 1 << endl;
		return 0;
	}
	sort(y, y + n);
	for (int i = 0; i < n; i++) {
		y2[i] = -y[n - i - 1];
	}
	long long now = y[0];
	for (int i = 1; i < n; i++) {
		if (i % 2 == 0) {
			l[i] += y[i / 2] - now;
			now = y[i / 2];
		}
		l[i] += l[i - 1];
		l[i] += y[i - 1] - y[i / 2];
	}
	now = y2[0];
	for (int i = 1; i < n; i++) {
		if (i % 2 == 0) {
			r[i] += y2[i / 2] - now;
			now = y2[i / 2];
		}
		r[i] += r[i - 1];
		r[i] += y2[i - 1] - y2[i / 2];
	}
	long long ans = 100000000000000007;
	for (int i = 1; i < n; i++) {
		ans = min(ans, l[i] + r[n - i]);
	}
	cout << ans << endl;
}
0