結果
| 問題 | No.3697 実力を揃える |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-09 22:45:09 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 1,125 ms / 5,000 ms |
| + 808µs | |
| コード長 | 944 bytes |
| 記録 | |
| コンパイル時間 | 3,675 ms |
| コンパイル使用メモリ | 188,076 KB |
| 実行使用メモリ | 101,888 KB |
| 最終ジャッジ日時 | 2026-09-09 22:45:28 |
| 合計ジャッジ時間 | 10,989 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
using ll = long long;
using P = pair<int, int>;
vector<set<ll>> all(vector<ll>& a){
int n=a.size();
vector<set<ll>> ans(n+1);
int mx=(1<<n);
for(int i=0; i<mx; i++){
ll now=0, c=0;
for(int j=0; j<n; j++)if(i>>j&1) c++, now+=a[j];
ans[c].insert(now);
}
return ans;
}
int main(void){
int n; cin >> n;
vector<ll> pre, aft;
ll sum=0;
for(int i=0; i<n; i++){
ll x; cin >> x; sum+=x;
if(i<n/2) pre.push_back(x);
else aft.push_back(x);
}
auto s1=all(pre);
auto s2=all(aft);
ll ans=1e18;
for(int i=0; i<=n/2; i++){
for(auto p:s1[i]){
ll x=sum-p*2, opp=n/2-i;
auto it=s2[opp].upper_bound(x/2);
if(it!=end(s2[opp])) ans=min(ans, abs(x-2**(it)));
if(it!=begin(s2[opp])) it--;
if(it!=end(s2[opp])) ans=min(ans, abs(x-2**(it)));
}
}
cout << ans << endl;
return 0;
}