結果

問題 No.545 ママの大事な二人の子供
コンテスト
ユーザー T
提出日時 2026-10-28 19:23:58
言語 C++23(gcc16)
(gcc 16.2.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc16.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 2,013 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,371 ms
コンパイル使用メモリ 228,320 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-28 19:24:06
合計ジャッジ時間 6,881 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 9 WA * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <cmath>
#include <climits>
#define ALL(variable) (variable).begin(), (variable).end()
#define GT(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName < (int)limit; variableName++)
#define GTE(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName <= (int)limit; variableName++)
#define LT(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName > (int)limit; variableName--)
#define LTE(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName >= (int)limit; variableName--)
using namespace std ;
int main(){
    long long n, answer;
    cin >> n;
    answer = LLONG_MAX;
    vector<long long> A(n), B(n);
    GT(i, 0, n){
        cin >> A[i] >> B[i];
    }

    vector<long long> upA(0), loA(0);
    GT(i, 0, pow(2, n/2)){
        long long memo = 0, _i = i;
        GT(j, 0, n/2)
        {
            if(_i%2 == 0){
                memo += A[j];
            }
            else{
                memo -= B[j];
            }
            _i = i>>1;
        }
        upA.push_back(memo);
    }
    GT(i, 0, pow(2, n-n/2)){
        long long memo = 0, _i = i;
        GT(j, 0, n-n/2)
        {
            if(_i%2 == 0){
                memo += A[j+n/2];
            }
            else{
                memo -= B[j+n/2];
            }
            _i = i>>1;
        }
        loA.push_back(memo);
    }
    sort(ALL(upA));
    sort(ALL(loA));
    GT(i, 0, upA.size()){
        int loi = lower_bound(ALL(loA), -upA[i])-loA.begin();
        int underloi = 0;
        if(loi != 0){
            int underloi = lower_bound(ALL(loA), -upA[i])-1-loA.begin();            
        }
        long long _ = min(abs(upA[i] + loA[loi]), abs(upA[i] + loA[underloi]));
        answer = min(answer, _);
    }
    cout << answer << endl;
    return 0;
}
0