結果
| 問題 | No.3697 実力を揃える |
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2026-09-09 21:43:29 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 185 ms / 5,000 ms |
| + 436µs | |
| コード長 | 1,499 bytes |
| 記録 | |
| コンパイル時間 | 7,766 ms |
| コンパイル使用メモリ | 366,804 KB |
| 実行使用メモリ | 23,424 KB |
| 最終ジャッジ日時 | 2026-09-09 21:43:47 |
| 合計ジャッジ時間 | 5,193 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include<bits/stdc++.h>
namespace {
#pragma GCC diagnostic ignored "-Wunused-function"
#include<atcoder/all>
#pragma GCC diagnostic warning "-Wunused-function"
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
} int main() {
ios::sync_with_stdio(false);
cin.tie(0);
VL d1[21], d2[21];
int n;
cin >> n;
rep(z, 2) {
VI a(n / 2);
rep(i, n / 2) cin >> a[i];
rep(s, 1 << (n / 2)) {
ll sm = 0;
rep(i, n / 2) {
if ((s >> i & 1) ^ z) sm += a[i];
else sm -= a[i];
}
d1[popcount(0U + s)].emplace_back(sm);
}
rep(i, n / 2 + 1) sort(all(d1[i]));
swap(d1, d2);
}
constexpr long long INF = 1002003004005006007;
ll ans = INF;
rep(i, n / 2 + 1) {
int j = n / 2 - i;
int ptr = 0;
for (ll x : d1[i]) {
while (ptr < ssize(d2[j]) && d2[j][ptr] < x) ptr++;
if (ptr) chmin(ans, x - d2[j][ptr-1]);
if (ptr < ssize(d2[j])) chmin(ans, d2[j][ptr] - x);
}
}
cout << ans << '\n';
}
Kude