結果

問題 No.545 ママの大事な二人の子供
ユーザー FF256grhyFF256grhy
提出日時 2017-07-14 23:14:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,558 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 167,412 KB
実行使用メモリ 10,704 KB
最終ジャッジ日時 2024-04-16 20:40:34
合計ジャッジ時間 2,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, a[32], b[32], ans;
vector<LL> v1, v2;

void f() {
	int j = 0;
	dec(i, v1.size()) {
		while(j < v2.size() - 1 && v1[i] + v2[j] < 0) { j++; }
		if(v1[i] + v2[j] < 0) { break; }
		setmin(ans, v1[i] + v2[j]);
	}
}

int main() {
	cin >> n;
	inc(i, n) { cin >> a[i] >> b[i]; }
	
	if(n == 1) { cout << min(a[0], b[0]) << endl; return 0; }
	
	set<LL> s1, s2;
	int m1 = n / 2;
	inc(bit, 1 << m1) {
		LL v = 0;
		inc(i, m1) {
			v += ((bit >> i) & 1 ? a[i] : -b[i]);
		}
		s1.insert(v);
	}
	
	int m2 = n - m1;
	inc(bit, 1 << m2) {
		LL v = 0;
		inc(i, m2) {
			v += ((bit >> i) & 1 ? a[m1 + i] : -b[m1 + i]);
		}
		s2.insert(v);
	}
	
	
	FOR(it, s1) { v1.PB(*it); }
	FOR(it, s2) { v2.PB(*it); }
	
	/*
	cout << v1.size() << " " << v2.size() << endl;
	inc(i, v1.size()) { cout << v1[i] << " "; } cout << endl;
	inc(i, v2.size()) { cout << v2[i] << " "; } cout << endl;
	*/
	
	ans = 1e15;
	f();
	inc(i, v2.size()) { v2[i] *= -1; }
	reverse(ALL(v2));
	f();
	
	cout << ans << endl;
	
	return 0;
}
0