結果

問題 No.545 ママの大事な二人の子供
ユーザー mamekinmamekin
提出日時 2017-07-14 22:35:44
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,465 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 109,636 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:35:37
合計ジャッジ時間 2,207 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 1 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 13 ms
5,376 KB
testcase_23 AC 25 ms
5,376 KB
testcase_24 AC 10 ms
5,376 KB
testcase_25 AC 22 ms
5,376 KB
testcase_26 AC 24 ms
5,376 KB
testcase_27 AC 17 ms
5,376 KB
testcase_28 AC 25 ms
5,376 KB
testcase_29 AC 20 ms
5,376 KB
testcase_30 AC 22 ms
5,376 KB
testcase_31 AC 20 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<long long> > x(2), y(2);
    for(int i=0; i<n; ++i){
        long long a, b;
        cin >> a >> b;
        x[i%2].push_back(a);
        y[i%2].push_back(b);
    }

    vector<vector<long long> > v(2);
    for(int i=0; i<2; ++i){
        int m = x[i].size();
        for(int j=0; j<(1<<m); ++j){
            bitset<32> bs(j);
            long long sum = 0;
            for(int k=0; k<m; ++k){
                if(bs[k])
                    sum += x[i][k];
                else
                    sum -= y[i][k];
            }
            v[i].push_back(sum);
        }
    }
    
    sort(v[0].begin(), v[0].end());
    long long ans = LLONG_MAX;
    for(long long a : v[1]){
        auto it = lower_bound(v[0].begin(), v[0].end(), -a);
        if(it != v[0].end())
            ans = min(ans, abs(a + *it));
        if(it != v[0].begin()){
            -- it;
            ans = min(ans, abs(a + *it));
        }
    }
    cout << ans << endl;

    return 0;
}
0