結果
| 問題 |
No.545 ママの大事な二人の子供
|
| コンテスト | |
| ユーザー |
hiyokko2
|
| 提出日時 | 2017-07-14 23:23:37 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,337 bytes |
| コンパイル時間 | 1,409 ms |
| コンパイル使用メモリ | 165,880 KB |
| 実行使用メモリ | 11,552 KB |
| 最終ジャッジ日時 | 2024-10-07 23:55:01 |
| 合計ジャッジ時間 | 7,305 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 TLE * 1 -- * 9 |
ソースコード
#include <bits/stdc++.h>
#define FOR(i,bg,ed) for(ll i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define int long long
using namespace std;
typedef long long ll;
const int INF = 1e9;
int n;
int A[40], B[40];
set<int> foo;
int ans = 7e9;
void dfs(int i, int t, int a, int b)
{
if (n == 1) {
foo.insert(0);
return;
}
if (i == t) {
foo.insert(b - a);
return;
}
dfs(i + 1, t, a + A[i], b);
dfs(i + 1, t, a, b + B[i]);
}
void dfs2(int i, int t, int a, int b)
{
//cout << "i = " << i << endl;
if (i == t) {
int b_a = b - a;
auto it = lower_bound(foo.begin(), foo.end(), -b_a);
if (it == foo.end()) {
it--;
}
//cout << "AAA = " << *it << endl;
//cout << "b_a = " << b_a << endl;
ans = min(ans, abs(-b_a - *it));
if (it != foo.begin()) {
it--;
ans = min(ans, abs(-b_a - *it));
}
return;
}
dfs2(i + 1, t, a + A[i], b);
dfs2(i + 1, t, a, b + B[i]);
}
signed main()
{
cin >> n;
REP(i,n) cin >> A[i] >> B[i];
dfs(0, n / 2, 0, 0);
//cout << "BBB" << endl;
//for (auto it=foo.begin(); it!=foo.end(); it++) {
// cout << *it << endl;
//}
dfs2(n / 2, n, 0, 0);
cout << ans << endl;
}
hiyokko2