結果

問題 No.837 Noelちゃんと星々2
ユーザー ktr216ktr216
提出日時 2019-06-14 23:06:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,377 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 171,276 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 21:45:40
合計ジャッジ時間 3,811 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

using ll = long long;

ll solve() {
    int N;
    cin >> N;
    vector<ll> Y(N);
    rep(i, N) cin >> Y[i];
    sort(Y.begin(), Y.end());
    if (Y[0] == Y[N - 1]) return 1;
    vector<ll> S(N + 1);
    S[0] = 0;
    rep(i, N) S[i + 1] = S[i] + Y[i];
    ll ret = 1e18;
    rep(i, N - 1) {
        if (Y[i] == Y[i + 1]) continue;
        ll sum1 = S[i + 1];
        ll mean1 = sum1 / (i + 1);
        if ((sum1 - mean1 * (i + 1)) * 2 >= i + 1) mean1++;
        int j = lower_bound(Y.begin(), Y.end(), mean1) - Y.begin();
        //cout << "j=" << j;
        ll dif = S[i + 1] - S[j] - mean1 * (i + 1 - j);
        //cout << " dif=" << dif;
        dif += mean1 * j - S[j];
        //cout << " dif=" << dif;
        ll sum2 = S[N] - S[i + 1];
        ll mean2 = sum2 / (N - i - 1);
        if ((sum2 - mean2 * (N - i - 1)) * 2 >= N - i - 1) mean2++;
        j = lower_bound(Y.begin(), Y.end(), mean2) - Y.begin();
        //cout << " j=" << j;
        dif += S[N] - S[j] - mean2 * (N - j);
        //cout << " dif=" << dif;
        dif += mean2 * (j - i - 1) - S[j] + S[i + 1];
        //cout << " dif=" << dif;
        ret = min(ret, dif);
        //cout << " i=" << i << " mean1=" << mean1 << " mean2=" << mean2 << endl; 
    }
    return ret;
}

int main() {
    cout << solve() << endl;
}
0