QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#366889 | #6510. Best Carry Player 3 | Ceased | WA | 0ms | 3844kb | C++17 | 1.6kb | 2024-03-25 13:50:44 | 2024-03-25 13:50:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e6 + 5;
ll x, y, k;
int a[100], b[100], c[100];
void run(){
cin >> x >> y >> k;
if (x > y) swap(x, y);
if (k <= 1 || x == y) {
cout << abs(x - y) << '\n';
return ;
}
if (x ^ y <= k) {
cout << "1\n";
}
ll cntx = 0, cnty = 0, cntk = 0;
ll t = x;
while (t) {
a[++ cntx] = (t & 1);
t >>= 1;
}
t = y;
while (t) {
b[++ cnty] = t & 1;
t >>= 1;
}
bool ok = 0;
t = k;
while (t) {
c[++ cntk] = t & 1;
if (!c[cntk]) ok = 1;
t >>= 1;
}
int cost = ok + 2;
ll res = 0;
for (int i = cnty; i > cntk; i -- ) {
if (b[i] == 1) res += (ll)pow(2, i - cntk - 1) * cost;
if (a[i] == 1) res -= (ll)pow(2, i - cntk - 1) * cost;
}
ll tmp = 1, sum = 0;
for (int i = 1; i <= cntk; i ++ ) {
if (!a[i]) sum += tmp;
tmp <<= 1;
}
if (sum == 0) res = res - cost + 1;
else if (sum <= k) res = res - cost + 2;
tmp = 1, sum = 0;
for (int i = 1; i <= cntk; i ++ ) {
if (b[i]) sum += tmp;
tmp <<= 1;
}
if (sum > k) res += 2;
else res += sum != 0;
cout << res << '\n';
for (int i = 1; i <= cnty; i ++ ) a[i] = b[i] = c[i] = 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int tcase = 1;
cin>>tcase;
while(tcase--) run();
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3844kb
input:
8 4 5 0 5 8 3 9 2 6 15 28 5 97 47 8 164 275 38 114514 1919 810 0 1152921504606846975 1
output:
1 1 2 1 3 1 5 1 11 1 6 1 331 1152921504606846975
result:
wrong answer 2nd numbers differ - expected: '2', found: '1'