結果
| 問題 |
No.545 ママの大事な二人の子供
|
| コンテスト | |
| ユーザー |
WA_TLE
|
| 提出日時 | 2017-07-14 22:35:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 39 ms / 2,000 ms |
| コード長 | 1,470 bytes |
| コンパイル時間 | 1,367 ms |
| コンパイル使用メモリ | 124,604 KB |
| 最終ジャッジ日時 | 2025-01-05 01:33:33 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 |
ソースコード
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<chrono>
#include<functional>
#include<random>
#include<unordered_set>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=1000000007;
const llint big=1e17-10;
const long double pai=3.141592653589793238462643383279;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
vector<llint>fdp;
vector<llint>cdp;
vector<llint>iti;
llint n,i,j;cin>>n;
fdp.pub(0);cdp.pub(0);
for(i=0;i<n/2;i++){
llint a,b;cin>>a>>b;
for(j=0;j<fdp.size();j++){
iti.pub(fdp[j]+a);
iti.pub(fdp[j]-b);
}
swap(fdp,iti);
iti.clear();
}
for(i=0;i<n-(n/2);i++){
llint a,b;cin>>a>>b;
for(j=0;j<cdp.size();j++){
iti.pub(cdp[j]+b);
iti.pub(cdp[j]-a);
}
swap(cdp,iti);
iti.clear();
}
sort(fdp.begin(),fdp.end());
sort(cdp.begin(),cdp.end());
llint ans=big;
for(i=0;i<fdp.size();i++){
auto it=lower_bound(cdp.begin(),cdp.end(),fdp[i]);
if(it!=cdp.end()){mineq(ans,abs((*it)-fdp[i]));}
if(it!=cdp.begin()){it--;mineq(ans,abs((*it)-fdp[i]));}
}
cout<<ans<<endl;
return 0;
}
WA_TLE