結果
| 問題 | No.545 ママの大事な二人の子供 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-28 19:23:58 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
WA
不安定
|
| 実行時間 | - |
| コード長 | 2,013 bytes |
| 記録 | |
| コンパイル時間 | 4,371 ms |
| コンパイル使用メモリ | 228,320 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-28 19:24:06 |
| 合計ジャッジ時間 | 6,881 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge5_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 23 |
ソースコード
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
#include <cmath>
#include <climits>
#define ALL(variable) (variable).begin(), (variable).end()
#define GT(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName < (int)limit; variableName++)
#define GTE(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName <= (int)limit; variableName++)
#define LT(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName > (int)limit; variableName--)
#define LTE(variableName, defaultValue, limit) for(int variableName = defaultValue; variableName >= (int)limit; variableName--)
using namespace std ;
int main(){
long long n, answer;
cin >> n;
answer = LLONG_MAX;
vector<long long> A(n), B(n);
GT(i, 0, n){
cin >> A[i] >> B[i];
}
vector<long long> upA(0), loA(0);
GT(i, 0, pow(2, n/2)){
long long memo = 0, _i = i;
GT(j, 0, n/2)
{
if(_i%2 == 0){
memo += A[j];
}
else{
memo -= B[j];
}
_i = i>>1;
}
upA.push_back(memo);
}
GT(i, 0, pow(2, n-n/2)){
long long memo = 0, _i = i;
GT(j, 0, n-n/2)
{
if(_i%2 == 0){
memo += A[j+n/2];
}
else{
memo -= B[j+n/2];
}
_i = i>>1;
}
loA.push_back(memo);
}
sort(ALL(upA));
sort(ALL(loA));
GT(i, 0, upA.size()){
int loi = lower_bound(ALL(loA), -upA[i])-loA.begin();
int underloi = 0;
if(loi != 0){
int underloi = lower_bound(ALL(loA), -upA[i])-1-loA.begin();
}
long long _ = min(abs(upA[i] + loA[loi]), abs(upA[i] + loA[underloi]));
answer = min(answer, _);
}
cout << answer << endl;
return 0;
}