結果

問題 No.3697 実力を揃える
コンテスト
ユーザー あるふぁ
提出日時 2026-09-13 10:35:20
言語 C++23(gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 715 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,932 ms
コンパイル使用メモリ 357,708 KB
実行使用メモリ 20,076 KB
最終ジャッジ日時 2026-09-13 10:35:32
合計ジャッジ時間 7,332 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 7 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (ll& x : A) cin >> x;

    int M = N/2;
    vector<ll> L(A.begin(), A.begin()+M);
    vector<ll> R(A.begin()+M, A.end());
    vector<ll> LS, RS;
    for (int bit = 0; bit < (1<<M); bit++){
        ll ls = 0, rs = 0;
        for (int i = 0; i < M; i++){
            if (bit>>i&1) ls += L[i], rs += R[i];
        }
        LS.push_back(ls);
        RS.push_back(rs);
    }

    ll S = reduce(A.begin(), A.end());
    ll res = 0;
    for (int x : LS){
        auto it = upper_bound(RS.begin(), RS.end(), S/2-x)-1;
        res = max(res, x+*it);
    }

    cout << S-2*res << endl;
}
0