結果

問題 No.545 ママの大事な二人の子供
ユーザー settsudsettsud
提出日時 2017-07-14 23:17:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 52 ms / 2,000 ms
コード長 1,007 bytes
コンパイル時間 1,523 ms
コンパイル使用メモリ 168,708 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-16 20:41:12
合計ジャッジ時間 2,650 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 1 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 3 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 6 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 25 ms
6,400 KB
testcase_23 AC 49 ms
9,344 KB
testcase_24 AC 20 ms
6,400 KB
testcase_25 AC 45 ms
9,600 KB
testcase_26 AC 52 ms
9,472 KB
testcase_27 AC 43 ms
9,472 KB
testcase_28 AC 48 ms
9,472 KB
testcase_29 AC 45 ms
9,472 KB
testcase_30 AC 52 ms
9,472 KB
testcase_31 AC 48 ms
9,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
set<long long int >get_all(vector<pair<long long int,long long int>>v) {
	set<long long int>aset;
	for (int i = 0; i < (1 << v.size()); ++i) {
		bitset<20>bs(i);
		long long int sum = 0;
		for (int j = 0; j < v.size(); ++j) {
			if (bs[j])sum += v[j].first;
			else sum -= v[j].second;
		}
		aset.emplace(sum);
	}
	return aset;
}
int main() {
	int N; cin >> N;
	vector<pair<long long int,long long int>>ds;
	for (int i = 0; i < N; ++i) {
		long long int a, b; cin >> a >> b;
		ds.emplace_back(a, b);
	}
	auto aset(get_all(vector<pair<long long int, long long int>>(ds.begin(), ds.begin() + N / 2)));
	auto bset(get_all(vector<pair<long long int, long long int>>(ds.begin() + N / 2, ds.end())));
	long long int ans = 1e18;
	for (auto as : aset) {
		auto it = bset.lower_bound(-as);
		if (it != bset.end()) {
			ans = min(ans, abs(*it+ as));
			
		}
		if (it != bset.begin()) {
			ans = min(ans, abs(*(prev(it))+ as));
		}
		
	}
	cout << ans << endl;
	return 0;
}
0