結果

問題 No.545 ママの大事な二人の子供
ユーザー WA_TLEWA_TLE
提出日時 2017-07-14 22:35:01
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 17 ms / 2,000 ms
コード長 1,470 bytes
コンパイル時間 1,334 ms
コンパイル使用メモリ 128,564 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 20:35:32
合計ジャッジ時間 2,384 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 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 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 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 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 10 ms
5,376 KB
testcase_23 AC 17 ms
5,376 KB
testcase_24 AC 8 ms
5,376 KB
testcase_25 AC 15 ms
5,376 KB
testcase_26 AC 17 ms
5,376 KB
testcase_27 AC 15 ms
5,376 KB
testcase_28 AC 17 ms
5,376 KB
testcase_29 AC 15 ms
5,376 KB
testcase_30 AC 14 ms
5,376 KB
testcase_31 AC 14 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0