結果

問題 No.837 Noelちゃんと星々2
ユーザー finefine
提出日時 2019-06-14 23:09:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 990 bytes
コンパイル時間 1,642 ms
コンパイル使用メモリ 174,100 KB
実行使用メモリ 9,460 KB
最終ジャッジ日時 2023-09-02 07:22:15
合計ジャッジ時間 3,469 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
9,388 KB
testcase_01 AC 34 ms
9,340 KB
testcase_02 AC 34 ms
9,420 KB
testcase_03 AC 35 ms
9,460 KB
testcase_04 AC 34 ms
9,452 KB
testcase_05 AC 35 ms
9,404 KB
testcase_06 AC 34 ms
9,332 KB
testcase_07 AC 34 ms
9,428 KB
testcase_08 AC 34 ms
9,456 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 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,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 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,380 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,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 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;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> y(n);
    for (int i = 0; i < n; i++) cin >> y[i];
    sort(y.begin(), y.end());

    set<ll> s(y.begin(), y.end());
    if (s.size() == 1) {
        cout << 1 << endl;
        return 0;
    } else if (s.size() == 2) {
        cout << 0 << endl;
        return 0;
    }

    vector<ll> sum(n + 1, 0);
    for (int i = 0; i < n; i++) {
        sum[i + 1] = sum[i] + y[i];
    }

    ll ans = 1e18;
    for (int i = 0; i < n - 1; i++) {
        int idx1 = i / 2;
        ll s1 = (idx1 * y[idx1] - sum[idx1]) + sum[i + 1] - sum[idx1 + 1] - (i - idx1) * y[idx1];

        int idx2 = i + 1 + (n - 1 - i) / 2;
        ll s2 = (idx2 - 1 - i) * y[idx2] - (sum[idx2] - sum[i + 1]) + sum[n] - sum[idx2 + 1] - (n - idx2 - 1) * y[idx2];
        
        ans = min(ans, s1 + s2);
    }    
    cout << ans << endl;
    return 0;
}
0