結果

問題 No.837 Noelちゃんと星々2
ユーザー Arumakan1727Arumakan1727
提出日時 2019-06-15 15:25:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 1,238 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 168,216 KB
実行使用メモリ 5,648 KB
最終ジャッジ日時 2023-09-02 07:25:20
合計ジャッジ時間 3,271 ms
ジャッジサーバーID
(参考情報)
judge16 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 23 ms
5,648 KB
testcase_01 AC 23 ms
5,336 KB
testcase_02 AC 23 ms
5,400 KB
testcase_03 AC 23 ms
5,336 KB
testcase_04 AC 23 ms
5,444 KB
testcase_05 AC 22 ms
5,332 KB
testcase_06 AC 22 ms
5,336 KB
testcase_07 AC 22 ms
5,332 KB
testcase_08 AC 23 ms
5,340 KB
testcase_09 AC 3 ms
4,956 KB
testcase_10 AC 3 ms
4,988 KB
testcase_11 AC 3 ms
5,008 KB
testcase_12 AC 3 ms
5,048 KB
testcase_13 AC 3 ms
4,988 KB
testcase_14 AC 3 ms
5,072 KB
testcase_15 AC 3 ms
5,080 KB
testcase_16 AC 3 ms
5,048 KB
testcase_17 AC 3 ms
4,956 KB
testcase_18 AC 3 ms
5,048 KB
testcase_19 AC 3 ms
4,944 KB
testcase_20 AC 3 ms
5,012 KB
testcase_21 AC 2 ms
5,136 KB
testcase_22 AC 3 ms
5,140 KB
testcase_23 AC 3 ms
4,952 KB
testcase_24 AC 3 ms
5,060 KB
testcase_25 AC 3 ms
4,948 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 3 ms
5,012 KB
testcase_28 AC 3 ms
4,944 KB
testcase_29 AC 3 ms
5,132 KB
testcase_30 AC 3 ms
4,992 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 3 ms
4,984 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;
// >>>

struct FastIO {
    FastIO() { cin.tie(nullptr); ios::sync_with_stdio(false); }
} fastIO_ydk ;

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; }

    i64 x[100010] {};
    i64 y[100010] {};

    for (int i = 1; i < N; ++i) x[i] = x[i-1] + a[i] - a[i/2];

    reverse(a, a+N);
    for (int i = 1; i < N; ++i) y[i] = y[i-1] - a[i] + a[i/2];

    reverse(y, y+N);

    i64 ans = LINF;
    for (int i = 0; i+1 < N; ++i) {
        chmin(ans, x[i] + y[i+1]);
    }

    cout << (ans) << endl;

    return 0;
}

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