結果

問題 No.837 Noelちゃんと星々2
ユーザー kibunakibuna
提出日時 2019-06-14 21:51:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 1,434 bytes
コンパイル時間 1,530 ms
コンパイル使用メモリ 170,712 KB
実行使用メモリ 4,692 KB
最終ジャッジ日時 2023-09-02 07:20:02
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vl y(n);
    for (int i = 0; i < n; ++i) {
        cin >> y[i];
    }
    sort(y.begin(), y.end());
    if (y[0] == y[n - 1]) {
        cout << 1 << "\n";
        return 0;
    }
    vl z = y;
    for (int i = 1; i < n; ++i) {
        z[i] += z[i - 1];
    }
    ll ret = 1LL << 60;
    for (int i = 1; i < n; ++i) {
        int xs = 0;
        int xm = i / 2;
        int xt = i;
        int ys = i;
        int ym = i + (n - i) / 2;
        int yt = n;
        ll leftmode = y[xm];
        ll rightmode = y[ym];
        ll leftleft = leftmode * (xm + 1) - z[xm];
        ll leftright = (z[xt - 1] - z[xm]) - (xt - 1 - xm) * leftmode;
        ll left = leftleft + leftright;
        ll rightleft = rightmode * (ym - ys + 1) - (z[ym] - z[ys - 1]);
        ll rightright = (z[yt - 1] - z[ym]) - (yt - 1 - ym) * rightmode;
        ll right = rightleft + rightright;
        chmin(ret, left + right);
    }
    cout << ret << "\n";
    return 0;
}
0