結果
| 問題 | No.3697 実力を揃える |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-09-13 10:45:14 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 242 ms / 5,000 ms |
| + 90µs | |
| コード長 | 1,063 bytes |
| 記録 | |
| コンパイル時間 | 2,591 ms |
| コンパイル使用メモリ | 367,964 KB |
| 実行使用メモリ | 21,936 KB |
| 最終ジャッジ日時 | 2026-09-13 10:45:36 |
| 合計ジャッジ時間 | 5,843 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
int N;
cin >> N;
vector<ll> A(N);
for (ll& x : A) cin >> x;
int M = N/2;
vector<ll> L(A.begin(), A.begin()+M);
vector<ll> R(A.begin()+M, A.end());
vector<vector<ll>> LS(M+1), RS(M+1);
for (int bit = 0; bit < (1<<M); bit++){
ll ls = 0, rs = 0, pc = 0;
for (int i = 0; i < M; i++){
if (bit>>i&1) ls += L[i], rs += R[i], pc++;;
}
LS[pc].push_back(ls);
RS[pc].push_back(rs);
}
for (auto& a : LS) sort(a.begin(), a.end());
for (auto& a : RS) sort(a.begin(), a.end());
ll S = reduce(A.begin(), A.end());
ll ans = LLONG_MAX;
for (int i = 0; i <= M; i++){
for (ll x : LS[i]){
ll tar = S/2-x;
auto it = lower_bound(RS[M-i].begin(), RS[M-i].end(), tar);
if (it != RS[M-i].end()) ans = min(ans, abs(S-2*(x+*it)));
if (it != RS[M-i].begin()) ans = min(ans, abs(S-2*(x+*(--it))));
}
}
cout << ans << endl;
}