QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#235977 | #6510. Best Carry Player 3 | ucup-team1883# | WA | 15ms | 3944kb | C++17 | 1.5kb | 2023-11-03 14:28:10 | 2023-11-03 14:28:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define LOG(f...) fprintf(stderr, f)
using ll = long long;
ll K;
int pos;
ll lU;
ll opt(ll x) {
ll cur = 1ULL << pos;
for (int i = pos - 1; i >= 0; --i) {
if ((x >> i) & 1) continue;
if ((cur | (1ULL << i)) <= K) cur |= 1ULL << i;
}
return x ^ cur;
}
ll solve(ll x, ll y) {
assert(x <= y);
if (x == y) return 0;
if ((x ^ y) <= K) return 1;
if (y == x + 1) return 1;
ll hx = x >> pos, hy = y >> pos;
ll lx = x & lU;//, ly = y & lU;
if (hy - hx > 1 && lx == 0) {
ll cnt = (hy - hx) / 2; // -1 boundary?
int nopt = ((K & lU) == lU ? 2 : 3);
return cnt * nopt + solve(x + (cnt << (pos + 1)), y);
}
if (lx == lU) {
if (hx & 1) return 1 + solve(x + 1, y);
else if (hy - hx > 1) return 1 + solve(opt(x), y);
}
assert(hy > hx);
if (hy - hx == 1) {
if (hx & 1)
return 2 + solve((hx + 1) << pos, y);
else
return 2;
}
if (hx & 1) return 2 + solve((hx + 1) << pos, y);
else {
{ // lx != 0
ll tx = opt(x);
if ((tx & lU) == lU) return 2 + solve(tx + 1, y);
else return 3 + solve((tx | lU) + 1, y);
}
}
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
ll x, y;
scanf("%lld%lld%lld", &x, &y, &K);
if (x > y) swap(x, y);
if (K == 0) { printf("%lld\n", y - x); continue; }
pos = 63 - __builtin_clzll(K); lU = (1LL << pos) - 1;
printf("%lld\n", solve(x, y));
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3944kb
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 2 3 5 11 6 331 1152921504606846975
result:
ok 8 numbers
Test #2:
score: -100
Wrong Answer
time: 15ms
memory: 3784kb
input:
100000 84 318 6 54 226 7 92 33 0 39 54 5 76 79 7 247 110 0 211 90 0 4 430 3 230 17 1 491 93 5 196 117 7 137 29 2 76 490 6 422 43 7 277 26 4 159 43 1 67 37 5 17 2 5 113 176 7 85 473 0 68 217 7 275 8 7 124 34 1 30 66 0 80 149 3 103 149 6 84 354 1 27 342 7 94 114 1 69 125 1 72 48 7 361 8 7 285 82 1 74 ...
output:
88 45 59 6 1 137 121 213 213 150 21 81 156 95 95 116 12 6 16 388 39 67 90 36 35 17 270 79 20 56 6 89 203 108 26 15 157 98 111 389 174 123 59 289 78 17 21 36 275 191 17 102 60 93 100 11 6 79 44 63 91 60 22 109 11 3 10 67 11 85 207 47 39 83 156 189 107 27 81 247 81 335 33 144 11 50 54 347 233 175 30 7...
result:
wrong answer 1st numbers differ - expected: '87', found: '88'