結果

問題 No.837 Noelちゃんと星々2
ユーザー NoiriNoiri
提出日時 2019-07-23 12:38:37
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,097 bytes
コンパイル時間 1,739 ms
コンパイル使用メモリ 170,936 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-07 12:33:31
合計ジャッジ時間 4,471 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 2 ms
4,384 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 AC 1 ms
4,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i, n){
        cin >> v[i];
    } 

    bool flag = true;
    rep(i, n-1) if(v[i] != v[i+1]) flag = false;
    if(flag){
        cout << "1" << endl;
        return 0;
    }

    sort(v.begin(), v.end());

    //for(auto x : v) cout << "v: " << x << endl;

    ll ans = 1e18;

    if(n%2 == 0){
        int R = (n-1) / 2;
        vector<int> a;
        a.push_back(v[R/2]);
        a.push_back(v[R + R/2 +1]);

        //cout << "a: " << a[0] << ", " << a[1] << endl;
        
        ll sum  = 0;
        rep(j, n) sum += min(abs(v[j] - a[0]), abs(v[j] - a[1]));
        ans = min(ans, sum);
        
    }
    else {
        int R = n/2;
        vector<int> a, b;

        //cout << "a: " << v[R/2] << ", " << v[n/2 + R/2 + 1] << endl;

        ll sum  = 0;
        rep(i, n) sum += min(abs(v[i] - v[R/2]), abs(v[i] - v[n/2 + R/2 + 1]));
        ans = sum;
    }

    cout << ans << endl;
    
}
0