結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 21:38:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 909 bytes |
| コンパイル時間 | 2,038 ms |
| コンパイル使用メモリ | 202,592 KB |
| 最終ジャッジ日時 | 2025-02-23 23:34:41 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll Upb(ll x, int c) {
if (x & (1ll << c)) {
return x;
}
return ((x >> c) | 1) << c;
}
ll Lwb(ll x, int c) {
if (x & (1ll << c)) {
return x;
}
ll b = x & ((1ll << c) - 1);
ll r = x - b - 1;
if (r < 0) {
return -(1ll << 61);
} else {
return r;
}
}
using P = pair<ll, int>;
void solve() {
int N;
ll X;
cin >> N >> X;
std::vector<P> L, R;
for (int i = 0; i < N; i ++) {
int c;
cin >> c;
L.emplace_back(Lwb(X, c), i);
R.emplace_back(Upb(X, c), i);
}
R.emplace_back(X, N);
sort(L.begin(), L.end());
sort(R.begin(), R.end());
vector<int> did(N + 1, 0);
ll ans = (1ll << 61);
for (auto [l, i] : L) {
did[i] = 1;
while (did[R.back().second]) {
R.pop_back();
}
ans = min(ans, abs(X - l) + abs(R.back().first - X));
}
cout << ans * 2 << endl;
}
int main () {
int T;
cin >> T;
while (T--) solve();
}