結果
| 問題 |
No.2844 Birthday Party Decoration
|
| ユーザー |
gyouzasushi
|
| 提出日時 | 2024-08-23 22:01:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,211 bytes |
| コンパイル時間 | 1,809 ms |
| コンパイル使用メモリ | 197,996 KB |
| 最終ジャッジ日時 | 2025-02-23 23:47:03 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 4 |
ソースコード
#include <bits/stdc++.h>
#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) (x).begin(), (x).end()
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
string YesNo(bool cond) {
return cond ? "Yes" : "No";
}
string YESNO(bool cond) {
return cond ? "YES" : "NO";
}
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <typename T, class F>
T bisect(T ok, T ng, const F& f) {
while (abs(ok - ng) > 1) {
T mid = min(ok, ng) + (abs(ok - ng) >> 1);
(f(mid) ? ok : ng) = mid;
}
return ok;
}
template <typename T>
T floor_div(const T a, const T b) {
assert(b != 0);
return a / b - static_cast<T>((a ^ b) < 0 && a % b != 0);
}
template <typename T>
T ceil_div(const T a, const T b) {
assert(b != 0);
return a / b + static_cast<T>((a ^ b) >= 0 && a % b != 0);
}
template <typename T>
bool a_mul_b_eq_c(const T a, const T b, const T c) {
return c % a == 0 && b == c / a;
}
template <typename T>
bool a_mul_b_le_c(const T a, const T b, const T c) {
return b <= floor_div(c, a);
}
template <typename T>
bool a_mul_b_lt_c(const T a, const T b, const T c) {
return a_mul_b_le_c(a, b, c) && !a_mul_b_eq_c(a, b, c);
}
template <typename T>
bool a_mul_b_ge_c(const T a, const T b, const T c) {
return !a_mul_b_lt_c(a, b, c);
}
template <typename T>
bool a_mul_b_gt_c(const T a, const T b, const T c) {
return !a_mul_b_le_c(a, b, c);
}
template <class T>
vector<T> make_vec(size_t a) {
return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
is >> v[i];
}
return is;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
for (int i = 0; i < int(v.size()); i++) {
os << v[i];
if (i < sz(v) - 1) os << ' ';
}
return os;
}
int solve() {
int n;
ll x;
cin >> n >> x;
vector<pair<ll, ll>> p;
rep(i, n) {
int c;
cin >> c;
ll target_l = x;
ll target_r = x;
if (~x >> c & 1) {
target_r ^= 1 << c;
target_r >>= c;
target_r <<= c;
target_l = target_r;
target_l -= 1 << (c + 1);
}
// cerr << target_l << ' ' << target_r << '\n';
p.emplace_back(target_l, target_r);
}
ll ans = LINF;
rep(i, n + 1) {
ll min_l = i == n ? x : p[i].first;
ll max_r = x;
for (auto [l, r] : p) {
if (l < min_l) {
chmax(max_r, r);
}
}
chmin(ans, (abs(x - min_l) + abs(x - max_r)) * 2);
}
cout << ans << '\n';
return 0;
}
int main() {
int tt;
cin >> tt;
while (tt--) solve();
}
gyouzasushi