結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-08-23 22:19:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,100 bytes |
| コンパイル時間 | 1,973 ms |
| コンパイル使用メモリ | 196,772 KB |
| 最終ジャッジ日時 | 2025-02-23 23:58:32 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
lint INF = 1000000000000000000;
lint nearL(lint x, lint i) {
lint a = (1LL << i), b = (1LL << (i + 1LL));
if (x & a) {
return x;
}
lint q = (x - (b - 1)) / b;
lint res = b * q + (b - 1);
return (res >= 0 ? res : INF);
}
lint nearR(lint x, lint i) {
lint a = (1LL << i), b = (1LL << (i + 1LL));
if (x & a) {
return x;
}
lint q = (x - a) / b;
if (b * q + a < x) {
q++;
}
return b * q + a;
}
int main() {
int t;
cin >> t;
while (t--) {
lint n, x;
cin >> n >> x;
vector<lint> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
vector<lint> l(n), r(n);
for (int i = 0; i < n; i++) {
l[i] = nearL(x, c[i]);
r[i] = nearR(x, c[i]);
}
lint ml = *min_element(l.begin(), l.end()), mr = *max_element(r.begin(), r.end());
lint dl = abs(x - ml), dr = abs(x - mr);
cout << min({2 * dl + 2 * dr, 2 * dl, 2 * dr}) << endl;
}
}
Tatsu_mr