結果
問題 | No.545 ママの大事な二人の子供 |
ユーザー | kotatsugame |
提出日時 | 2017-07-14 23:35:31 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 748 bytes |
コンパイル時間 | 864 ms |
コンパイル使用メモリ | 77,284 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-07 23:40:29 |
合計ジャッジ時間 | 1,987 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 32 |
コンパイルメッセージ
main.cpp:9:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 9 | main() | ^~~~
ソースコード
#include<iostream> #include<algorithm> #include<vector> using namespace std; long a[32],b[32]; int n; vector<long>G; long ans=1e12; main() { cin>>n; for(int i=0;i<n;i++) { cin>>a[i]>>b[i]; } for(long i=0;i<1<<(n/2);i++) { long now=0; for(int j=0;j<n/2;j++) { if(i&(1<<j))now+=a[j]; else now-=b[j]; } G.push_back(now); } sort(G.begin(),G.end()); G.erase(unique(G.begin(),G.end()),G.end()); for(int i=0;i<1<<(n-n/2);i++) { long now=0; for(int j=0;j<n-n/2;j++) { if(i&(1<<j))now+=a[j+n/2]; else now-=b[j+n/2]; } now=-now; vector<long>::iterator it=lower_bound(G.begin(),G.end(),now); if(it!=G.end())ans=min(ans,abs(-now+*it)); it--; if(it!=G.end())ans=min(ans,abs(-now+*it)); } cout<<ans<<endl; }