結果
| 問題 |
No.2844 Birthday Party Decoration
|
| コンテスト | |
| ユーザー |
tama04
|
| 提出日時 | 2024-08-23 23:00:45 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,062 bytes |
| コンパイル時間 | 3,373 ms |
| コンパイル使用メモリ | 277,448 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-08-23 23:01:08 |
| 合計ジャッジ時間 | 3,837 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | WA * 4 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, s, n) for(int i = (s); i < n; i++)
int main(void) {
int t;
cin >> t;
int n;
ll x;
vector<ll> ans;
rep(i, 0, t) {
cin >> n >> x;
vector<ll> c(n);
rep(j, 0, n) {
cin >> c[j];
c[j] = (1LL << c[j]);
}
ll res = 0;
//cout << "t = " << i << endl;
rep(k, 0, n) {
//cout << " k = " << k << " c = " << c[k] << endl;
if ((x & c[k]) == 0) {
ll temp = 0;
for (int bit = 0; bit < 60; bit++) {
temp |= (x & (1LL << bit));
ll p1 = -1, p2 = -1;
if (c[k] & (1LL << bit)) {
p1 = (1LL << bit) - temp;
if (x > c[k]) {
p2 = x - ((1LL << (bit + 1)) - 1);
if (p2 < p1) {
res += p2;
x -= p2;
}
else {
res += p1;
x += p1;
}
}
else {
res += p1;
x += p1;
}
}
}
//cout << " temp = " << temp << " res = " << res << endl;
}
}
ans.push_back(res * 2);
}
rep(i, 0, ans.size()) {
cout << ans[i] << endl;
}
return 0;
}
tama04