QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278316 | #6510. Best Carry Player 3 | ucup-team1321# | WA | 18ms | 3804kb | C++23 | 2.5kb | 2023-12-07 14:48:36 | 2023-12-07 14:48:37 |
Judging History
answer
#include <bits/stdc++.h>
#ifndef LOCAL
#define debug(...) 42
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif
#define rep1(a) for (auto i = 0; i < a; i++)
#define rep2(i, a) for (auto i = 0; i < a; i++)
#define rep3(i, a, b) for (auto i = a; i < b; i++)
#define rep4(i, a, b, c) for (auto i = a; i < b; i += c)
#define overload4(a, b, c, d, e, ...) e
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define pb emplace_back
using namespace std;
template <typename T, typename T2> void cmin(T &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T, typename T2> void cmax(T &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
template <class T> using vc = vector<T>;
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
mt19937 rng(time(NULL));
const int inf = 1000000000;
const ll lnf = 1000000000000000000;
#define sz(x) int((x).size())
#define all(x) begin(x), end(x)
#define fi first
#define se second
void solve() {
ll X, Y, K;
cin >> X >> Y >> K;
if (K <= 1) {
cout << abs(Y - X) << "\n";
return;
}
if (X > Y) swap(X, Y);
K += 1;
ll K2 = 1;
while (K2 < K) {
K2 = K2 * 2;
}
K -= 1;
K2 -= 1;
// debug(K, K2);
ll ans = 0;
for (int i = 60; i >= 0; i--) {
ll base = 1LL << i;
if (K2 & base) {
break;
}
if ((Y & base) == base && ((X & base) == 0LL)) {
ll rem = Y & K2;
if (rem == 0) {
} else if (rem <= K) {
Y -= rem;
ans += 1;
} else {
Y -= rem;
ans += 2;
}
rem = (Y - base) / (K2 + 1);
ans += rem * 3;
Y = base - 1;
ans += 1;
// debug(X, Y, K, K2, ans);
} else {
Y &= ~base;
X &= ~base;
}
}
// debug(X, Y, K, K2, ans);
ll res = 2;
for (int i = -2; i <= 2; i++) {
for (int j = -2; j <= 2; j++) {
ll x = X + i;
ll y = Y + j;
if (x < 0) continue;
if (y < 0) continue;
ll k = 3;
if (x == y) k = 0;
else if ((x ^ y) <= K) k = 1;
else k = 2;
cmin(res, abs(i) + abs(j) + k);
}
}
cout << ans + res << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
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: 18ms
memory: 3804kb
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:
87 64 59 6 1 137 121 313 213 150 29 81 156 138 95 116 12 6 22 388 54 95 90 36 48 17 270 114 20 56 7 128 203 108 26 15 157 98 160 389 174 123 59 289 78 17 28 50 275 191 17 102 60 93 100 14 6 79 44 63 91 60 22 109 11 3 10 95 11 85 207 47 39 83 156 189 155 27 116 247 116 335 46 144 11 71 54 347 233 258...
result:
wrong answer 2nd numbers differ - expected: '45', found: '64'