QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303633 | #6510. Best Carry Player 3 | xuqin | WA | 19ms | 3872kb | C++14 | 2.0kb | 2024-01-12 20:30:52 | 2024-01-12 20:30:52 |
Judging History
answer
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<utility>
#include<ctime>
#include<vector>
#include<queue>
#include<iostream>
#include<set>
#include<random>
#include<cmath>
#include<chrono>
#include<map>
#define eb emplace_back
using namespace std;
const int maxn=2e3+10, maxm=2e5+10, P=998244353, inf=2e9;
typedef long long LL;
const LL INF=4e18;
typedef pair<int, int> pii;
typedef pair<LL, int> pli;
typedef pair<int, LL> pil;
inline int read() {
int x=0, f=1; char c=getchar();
for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=0;
for(; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
return f?x:-x;
}
inline int add(int x, int y) {x+=y; return x>=P?x-P:x;}
inline int del(int x, int y) {x-=y; return x<0?x+P:x;}
inline int ksm(int x, int y) {
int s=1; for(; y; y>>=1, x=1LL*x*x%P) if(y&1) s=1LL*s*x%P; return s;
}
mt19937 rnd((unsigned)chrono::steady_clock::now().time_since_epoch().count());
int main() {
int T=read();
while(T--) {
LL x, y, k;
scanf("%lld%lld%lld", &x, &y, &k);
if(x>y) swap(x, y);
if(k<=1||x==y) printf("%lld\n", y-x);
else {
int t=0; LL tmp=k;
while(tmp) tmp>>=1, ++t;
LL tx=x>>(t-1), ty=y>>(t-1);
if(tx==ty) printf("1\n");
else {
LL b=3;
if((k&(k+1))==0) b=2;
if((tx>>1)==(ty>>1)) {
if((y^x)<=k||x+1==y) printf("1\n");
else printf("2\n");
} else {
LL ans=0;
//printf("tx=%lld ty=%lld\n", tx, ty);
if(tx&1) {
if(((x^(tx<<(t-1)))&((x^(tx<<(t-1)))+1))==0) ans=1;
else ans=2;
++tx;
x=tx<<t;
} else {
if((((1<<t)-1)^(x&((1<<t)-1)))<=k) ans=2;
else ans=3;
tx+=2; x=tx<<t;
}
//printf("b=%lld\n", b);
//printf("ans=%lld\n", ans);
ans+=((ty>>1)-(tx>>1))*b;
x=x&((1<<t)-1), y=y&((1<<t)-1);
if(x==y) printf("%lld\n", ans);
else if((y^x)<=k||x+1==y) printf("%lld\n", 1+ans);
else printf("%lld\n", 2+ans);
}
}
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
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: 19ms
memory: 3872kb
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:
86 45 59 6 1 137 121 213 213 149 20 81 155 95 95 116 11 6 16 388 38 67 90 36 35 17 270 79 20 56 6 89 203 108 26 15 157 98 111 389 174 122 59 288 78 17 21 35 275 191 17 102 60 92 100 11 5 79 44 63 91 60 22 109 11 3 10 67 11 85 207 47 38 83 156 189 106 27 81 247 81 335 32 144 11 49 54 347 233 175 30 7...
result:
wrong answer 1st numbers differ - expected: '87', found: '86'