結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-08-23 22:59:29 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 11 ms / 2,000 ms |
| コード長 | 1,130 bytes |
| コンパイル時間 | 1,080 ms |
| コンパイル使用メモリ | 110,692 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-08-23 22:59:31 |
| 合計ジャッジ時間 | 1,630 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 4 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MAX_N = 60;
int N;
ll X, lb, ans;
int c[MAX_N];
int t;
void solve();
int main() {
cin >> t;
for (int tt = 0; tt < t; tt++)
solve();
return 0;
}
void solve() {
cin >> N >> X;
for (int i = 0; i < N; i++)
cin >> c[i];
vector<P> shops;
for (int i = 0; i < N; i++) {
ll tmp = (1LL << c[i]);
if (X & tmp)
continue;
ll q = X / tmp;
ll pos1 = (q + 1) * tmp;
ll pos2 = ((q == 0) ? 0 : (q - 1) * tmp + (tmp - 1));
shops.push_back(make_pair(pos1, pos2));
}
if (shops.empty()) {
cout << 0 << endl;
return;
}
sort(shops.begin(), shops.end(), greater<P>());
shops.push_back(make_pair(X, 0));
lb = X; ans = (shops[0].first - X) * 2;
for (int i = 0; i + 1 < shops.size(); i++) {
if (shops[i].second == 0)
break;
lb = min(lb, shops[i].second);
ans = min(ans, (shops[i + 1].first - lb) * 2);
}
cout << ans << endl;
}