結果
| 問題 | No.2918 Divide Applicants Fairly |
| ユーザー |
|
| 提出日時 | 2024-09-20 17:58:00 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 1,296 ms / 2,000 ms |
| コード長 | 1,006 bytes |
| 記録 | |
| コンパイル時間 | 3,560 ms |
| コンパイル使用メモリ | 282,596 KB |
| 実行使用メモリ | 70,104 KB |
| 最終ジャッジ日時 | 2024-10-07 21:06:19 |
| 合計ジャッジ時間 | 9,069 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int popcnt(int x) { return __builtin_popcount(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
template <class T, class S>
inline bool chmin(T &a, const S &b) {
return (a > b ? a = b, 1 : 0);
}
int main() {
int N;
cin >> N;
vector<int> R(N);
for (int &r : R) cin >> r;
if (N > 26) {
cout << 0 << endl;
return 0;
}
vector<int> comb;
function<void(int, int)> exh = [&](int bit, int sum) {
if (popcnt(bit) == N / 2) {
comb.emplace_back(sum);
} else {
for (int i = topbit(bit) + 1; i < N - N / 2 + popcnt(bit) + 1; ++i) {
exh(bit | (1 << i), sum + R[i]);
}
}
};
exh(0, 0);
sort(comb.begin(), comb.end());
int ans = 1 << 30;
for (int i = 0; i < comb.size() - 1; ++i) {
chmin(ans, abs(comb[i] - comb[i + 1]));
}
cout << ans << endl;
}