結果

問題 No.545 ママの大事な二人の子供
ユーザー kkey000kkey000
提出日時 2023-05-20 11:08:25
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,598 bytes
コンパイル時間 856 ms
コンパイル使用メモリ 78,468 KB
実行使用メモリ 4,684 KB
最終ジャッジ日時 2023-08-23 08:23:29
合計ジャッジ時間 6,145 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
void halr_sum(vector<long long int> a,vector<long long int> b,long long int temp_sum,int i,int end, vector<long long int> &sum){
    if(i==end){

        sum.push_back(temp_sum);

        return;
    }

    halr_sum(a,b,temp_sum + a[i],i+1,end,sum);
    halr_sum(a,b,temp_sum - b[i],i+1,end,sum);
}
int main(){
    int n;
    cin >> n;
    vector<long long int> a(n),b(n);
    for(int i=0; i<n; i++){
        cin >> a[i]>>b[i];
    }

    int lc=n/2,rc=n-lc;
    vector<long long int> l(lc),r(rc);

    vector<long long int> lsum,rsum;

    halr_sum(a,b,0,0,lc,lsum);
    halr_sum(a,b,0,lc,n,rsum);


    sort(lsum.begin(),lsum.end());
    sort(rsum.begin(),rsum.end());

    cout << "--" << endl;
    for(int k = 0; k < lsum.size(); k++){
        cout << lsum[k] << endl;
    }
    cout << "--" << endl;
    for(int k = 0; k < rsum.size(); k++){
        cout << rsum[k] << endl;
    }
    cout << "--" << endl;
    long long ans = 5000000000;
    int rnum = rsum.size()-1;
    int lnum = 0;
    while(lnum < lsum.size() && rnum > 0){
        if(llabs(lsum[lnum] + rsum[rnum]) > llabs(lsum[lnum] + rsum[rnum - 1])){
            rnum--;
        }else{
            ans = min(ans,llabs(lsum[lnum] + rsum[rnum]));
            cout << ans << " : " << lsum[lnum] << "," << rsum[rnum]<<endl;
            cout << "l : " << lnum << " r : " << rnum << endl;
            lnum++;
        }
    }
    if(lnum < lsum.size()){
        ans = min(ans,llabs(lsum[lnum] + rsum[rnum]));
    }


    cout << ans << endl;
    return 0;
}

0