結果
問題 | No.2844 Birthday Party Decoration |
ユーザー |
![]() |
提出日時 | 2024-08-23 22:29:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,150 bytes |
コンパイル時間 | 2,007 ms |
コンパイル使用メモリ | 197,012 KB |
最終ジャッジ日時 | 2025-02-24 00:01:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | WA * 4 |
ソースコード
#include <bits/stdc++.h>using namespace std;using lint = long long;lint INF = 3000000000000000000;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;if (b * q + (b - 1) > x) {q--;}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;}}