結果

問題 No.837 Noelちゃんと星々2
ユーザー phsplsphspls
提出日時 2020-05-03 22:53:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 859 bytes
コンパイル時間 2,534 ms
コンパイル使用メモリ 170,808 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-05 07:37:28
合計ジャッジ時間 5,312 ms
ジャッジサーバーID
(参考情報)
judge12 / 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 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,384 KB
testcase_17 WA -
testcase_18 AC 2 ms
4,380 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,384 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    llong n;
    cin >> n;
    vector<llong> y(n);
    rep(i, n) cin >> y[i];
    
    sort(y.begin(), y.end());
    if(y[0] == y[n-1]) {
        cout << "1\n";
    } else {
        llong maxdiff = 0;
        //前の方
        int idx = -1;
        rep(i, n-1) {
            if(maxdiff <= y[i+1] - y[i]) {
                if((maxdiff < y[i+1] - y[i]) || (abs(idx - n/2) > abs(i - n/2))) idx = i;
                maxdiff = y[i+1] - y[i];
            }
        }
        int bef = y[idx / 2];
        int aft = y[(idx+n) / 2];
        llong result = 0;
        rep(i, n) {
            if(i <= idx) result += abs(bef - y[i]);
            else result += abs(aft - y[i]);
        }
        cout << result << "\n";
    }
}
0