結果
| 問題 | No.545 ママの大事な二人の子供 |
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2020-11-27 08:05:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 968 bytes |
| コンパイル時間 | 780 ms |
| コンパイル使用メモリ | 77,416 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-23 21:22:50 |
| 合計ジャッジ時間 | 2,004 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 10 WA * 22 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long INF = 1000000000000;
int main(){
int n;
cin >> n;
vector<long long> A(n), B(n);
for (int i = 0; i < n; i++){
cin >> A[i] >> B[i];
}
int x = n / 2;
int y = n - x;
vector<long long> p(1 << x, 0);
for (int i = 0; i < (1 << x); i++){
for (int j = 0; j < x; j++){
if (i >> j){
p[i] += A[j];
} else {
p[i] -= B[j];
}
}
}
vector<long long> q(1 << y, 0);
for (int i = 0; i < (1 << y); i++){
for (int j = 0; j < y; j++){
if (i >> j){
q[i] += A[x + j];
} else {
q[i] -= B[x + j];
}
}
}
sort(p.begin(), p.end());
sort(q.begin(), q.end());
long long ans = INF;
for (int i = 0; i < (1 << x); i++){
auto itr = lower_bound(q.begin(), q.end(), -p[i]);
if (itr != q.end()){
ans = min(ans, abs(p[i] + *itr));
}
if (itr != q.begin()){
ans = min(ans, abs(p[i] + *prev(itr)));
}
}
cout << ans << endl;
return 0;
}
SSRS