結果
| 問題 | No.3697 実力を揃える |
| コンテスト | |
| ユーザー |
shinchan
|
| 提出日時 | 2026-09-09 21:28:19 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 244 ms / 5,000 ms |
| + 715µs | |
| コード長 | 2,370 bytes |
| 記録 | |
| コンパイル時間 | 2,220 ms |
| コンパイル使用メモリ | 342,632 KB |
| 実行使用メモリ | 12,800 KB |
| 最終ジャッジ日時 | 2026-09-09 21:29:47 |
| 合計ジャッジ時間 | 5,268 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define pb emplace_back
#define rep(i, n) for(int i=0;i<(n);i++)
#define foa(e, v) for(auto& e : v)
#define dout(a) cout<<fixed<<setprecision(10)<<a<<'\n';
#define Cout(a) cout<<a<<'\n';
using ll = long long;
using ld = long double;
using Int = __int128;
template <class T> using pqr = priority_queue<T, vector<T>, greater<T>>;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
bool compare = a < b;
if(compare) a = b;
return compare;
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
bool compare = a > b;
if(compare) a = b;
return compare;
}
template <typename T> inline T back(std::set<T> &s) {
return *s.rbegin();
}
template <typename T> inline T back(std::multiset<T> &s) {
return *s.rbegin();
}
template <typename T> inline T pop_back(std::set<T> &s) {
auto it = prev(s.end());
T val = *it;
s.erase(it);
return val;
}
template <typename T> inline T pop_back(std::multiset<T> &s) {
auto it = prev(s.end());
T val = *it;
s.erase(it);
return val;
}
const int dy[8] = {-1, 0, 0, 1, 1, -1, 1, -1};
const int dx[8] = {0, -1, 1, 0, -1, -1, 1, 1};
const ll MOD7 = 1000000007, MOD998 = 998244353, INF = (3LL << 59);
const int inf = 1 << 30;
const char br = '\n';
void solve() {
ll n;cin >> n;
vector<ll> a(n);
rep(i, n) cin >> a[i];
ll ans = INF;
vector<vector<ll>> v(n + 1);
int m = n / 2;
rep(bit, 1 << m) {
ll num = 0;
rep(j, m) {
if(bit >> j & 1) num += a[j];
else num -= a[j];
}
v[__builtin_popcount(bit)].pb(num);
}
rep(i, n) sort(all(v[i]));
rep(bit, 1 << (n - m)) {
ll num = 0;
rep(i, n - m) {
if(bit >> i & 1) num += a[i + m];
else num -= a[i + m];
}
int id = __builtin_popcount(bit);
auto itr = lower_bound(all(v[id]), num);
if(itr != v[id].end()) {
chmin(ans, abs(*itr - num));
}
if(itr != v[id].begin()) {
itr --;
chmin(ans, abs(*itr - num));
}
}
cout << ans << endl;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int testcase = 1;
// cin >> testcase;
while(testcase --) solve();
return 0;
}
shinchan