結果

問題 No.545 ママの大事な二人の子供
ユーザー chocoruskchocorusk
提出日時 2018-10-10 00:29:04
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 814 ms
コンパイル使用メモリ 98,724 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 19:20:54
合計ジャッジ時間 1,762 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 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 11 ms
5,376 KB
testcase_23 AC 22 ms
5,376 KB
testcase_24 AC 9 ms
5,376 KB
testcase_25 AC 17 ms
5,376 KB
testcase_26 AC 19 ms
5,376 KB
testcase_27 AC 15 ms
5,376 KB
testcase_28 AC 21 ms
5,376 KB
testcase_29 AC 17 ms
5,376 KB
testcase_30 AC 19 ms
5,376 KB
testcase_31 AC 18 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	ll a[32], b[32];
	for(int i=0; i<n; i++) cin>>a[i]>>b[i];
	ll d1[1<<16];
	for(int i=0; i<(1<<(n/2)); i++){
		d1[i]=0;
		for(int j=0; j<n/2; j++){
			if(i&(1<<j)) d1[i]=d1[i]+a[j];
			else d1[i]=d1[i]-b[j];
		}
	}
	sort(d1, d1+(1<<(n/2)));
	ll ans=1e12;
	for(int i=0; i<(1<<(n-n/2)); i++){
		ll d=0;
		for(int j=0; j<n-n/2; j++){
			if(i&(1<<j)) d=d+a[n/2+j];
			else d=d-b[n/2+j];
		}
		int i1=lower_bound(d1, d1+(1<<(n/2)), -d)-d1;
		if(i1<(1<<(n/2))) ans=min(ans, abs(d1[i1]+d));
		if(i1>0) ans=min(ans, abs(d1[i1-1]+d));
	}
	cout<<ans<<endl;
	return 0;
}
0