結果

問題 No.837 Noelちゃんと星々2
ユーザー face4face4
提出日時 2019-06-15 19:28:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 848 bytes
コンパイル時間 679 ms
コンパイル使用メモリ 75,668 KB
実行使用メモリ 4,892 KB
最終ジャッジ日時 2023-09-02 07:25:38
合計ジャッジ時間 2,678 ms
ジャッジサーバーID
(参考情報)
judge11 / judge16
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; i++)  cin >> v[i];
    sort(v.begin(), v.end());
    if(v[0] == v[n-1]){
        cout << 1 << endl;
        return 0;
    }
    vector<ll> sum(n);
    sum[0] = v[0];
    for(int i = 1; i < n; i++)  sum[i] = sum[i-1] + v[i];
    auto f = [&](int l, int r)->ll{
        if(r < 0 || l >= n)  return 0;
        ll sub = (l == 0 ? 0 : sum[l-1]);
        return sum[r] - sub;
    };
    // [i, r] , pivot - k
    auto g = [&](int i, int j, int k)->ll{
        return v[k]*(k-i)-f(i,k-1)+f(k+1,j)-v[k]*(j-k);
    };
    ll ans = 1ll<<60;
    for(int i = 1; i < n; i++){
        ans = min(ans, g(0,i-1,i/2)+g(i,n-1,(n+i)/2));
    }
    cout << ans << endl;
    return 0;
}
0