QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#278355 | #6510. Best Carry Player 3 | ucup-team1321# | WA | 22ms | 3820kb | C++23 | 2.5kb | 2023-12-07 15:06:54 | 2023-12-07 15:06:54 |
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 coef = min(2LL + (K < K2), K2 + 1 - K);
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 * coef;
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: 3820kb
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: 22ms
memory: 3684kb
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:
62 26 59 6 1 137 121 113 213 150 13 57 108 52 95 116 12 6 10 388 24 39 90 36 22 14 270 44 20 56 5 50 203 108 26 15 157 98 62 389 174 123 59 197 78 17 14 22 186 191 17 102 43 93 72 8 6 56 44 63 91 60 22 109 11 3 10 39 11 85 207 34 39 58 156 189 59 27 46 247 46 335 20 144 9 29 39 235 158 92 18 41 129 ...
result:
wrong answer 1st numbers differ - expected: '87', found: '62'