結果

問題 No.545 ママの大事な二人の子供
ユーザー T1610T1610
提出日時 2019-03-23 02:11:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,266 bytes
コンパイル時間 1,770 ms
コンパイル使用メモリ 175,492 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 16:18:23
合計ジャッジ時間 3,584 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vl a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    int m = n / 2;
    vector<int> v(1<<m);
    rep(mask, 1<<m) {
        rep(i, m) {
            if(mask & (1<<i)) v[mask] += a[i];
            else v[mask] -= b[i];
        }
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());

    ll ans = 1e18;
    rep(mask, 1<<(n-m)) {
        ll tmp = 0LL;
        rep(i, n - m) {
            if(mask & (1<<i)) tmp += a[i+m];
            else tmp -= b[i+m];
        }
        auto it = lower_bound(all(v), -tmp);
        if(it != v.end()) ans = min(ans, abs(tmp + *it));
        if(it != v.begin()) ans = min(ans, abs(tmp + *(--it)));
    }
    cout << ans << endl;
    return 0;
}
0