結果

問題 No.837 Noelちゃんと星々2
ユーザー Arumakan1727Arumakan1727
提出日時 2019-06-15 12:48:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 1,864 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 171,060 KB
実行使用メモリ 4,992 KB
最終ジャッジ日時 2023-09-02 07:25:17
合計ジャッジ時間 3,951 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
// Custom Header <<<
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;
// >>>

using v64 = vector<long long>;

    template<class Array>
v64 ruisekiwa(const Array src, int N)
{
    v64 s(N, src[0]);
    for (int i = 1; i < N; ++i) s[i] = s[i-1] + src[i];
    return s;
}

// [l, r]
inline long long partSum(const v64 &s, int l, int r)
{
    if (l > r) swap(l, r);
    return s[r] - (l <= 0 ? 0 : s[l-1]);
}

signed main()
{
    int N;
    int a[100010];

    cin >> N;
    rep(i, 0, N) cin >> a[i];

    sort(a, a+N);
    if (a[0] == a[N-1]) {
        cout << (1) << endl;
        return 0;
    }
    v64 s = ruisekiwa(a, N);

    // [l, r)
    const auto medianDiffSum = [&](int l, int r) -> i64 {
        const int N = r - l;
        const int mid = (l + r) / 2;

        if (N == 1) {
            return 0;
        }
        if (N % 2 == 0) {
            return partSum(s, mid, r-1) - partSum(s, l, mid-1);
        } else {
            return partSum(s, mid+1, r-1) - partSum(s, l, mid-1);
        }
    };

    v64 ans; ans.reserve(N);
    for (int d = 1; d < N; ++d) {
        const auto x = medianDiffSum(0, d);
        const auto y = medianDiffSum(d, N);
        eprintf("[0, %d) = %2lld, [%d, N) = %2lld\n", d, x, d, y);
        ans.push_back(x + y);
    }

    cout << (*min_element(ALL(ans))) << endl;

    return 0;
}

/* vim:set foldmethod=marker foldmarker=<<<,>>> : */
0