QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#350196 | #6510. Best Carry Player 3 | LittleXi# | TL | 1ms | 3704kb | C++20 | 3.0kb | 2024-03-10 15:15:21 | 2024-03-10 15:15:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
ll X,Y,K;
void solve1()
{
int b = 60;
while((K & (1ll << b)) == 0) --b;
ll ans = 0;
while((Y >> (b+1)) - (X >> (b+1)) > 0)
{
if((X & K) == K) ++ans, ++X;
else
{
ans += 2; X = (X | K) + 1;
}
}
if(X != Y) ++ans;
cout << ans << endl;
}
void solve2()
{
int b = 60;
while((K & (1ll << b)) == 0) --b;
ll ans = 0;
while((Y >> b) - (X >> b) > 1)
{
//printf("now X=%d, ans=%d\n",X,ans);
if(X & (1ll << b))
{
ll mask = (1ll << b) - 1;
if((X & mask) == mask)
{
++ans; ++X;
}
else
{
ans += 2; X = (X | mask) + 1;
}
}
else
{
ll mask = (1ll << (b+1)) - 1;
if(((X & mask) ^ mask) <= K)
{
ans += 1; X |= mask;
}
else
{
X |= (1ll << b); ++ans;
}
// ll mask = (1ll << (b+1)) - 1;
// if(((X & mask) ^ mask) <= K)
// {
// ans += 2;
// X = (X | mask) + 1;
// }
// else
// {
// mask = (1ll << b) - 1;
// if((X & mask) == mask)
// {
// ++ans; ++X;
// }
// else
// {
// ans += 2; X = (X | mask) + 1;
// }
// }
}
//printf("now X=%d, ans=%d\n",X,ans);
}
if(X == Y)
{
cout << ans << endl;
return;
}
if((X >> b) == (Y >> b))
{
cout << ans+1 << endl;
return;
}
if((X ^ Y) <= K)
{
cout << ans+1 << endl;
return;
}
if(X + 1 == Y)
{
cout << ans+1 << endl;
return;
}
if(X & (1ll << b))
{
ll mask = (1ll << b) - 1;
if((Y & mask) == 0)
{
cout << ans+2 << endl;
}
else if((X & mask) == mask)
{
cout << ans+2 << endl;
}
else
{
cout << ans+3 << endl;
}
return;
}
cout << ans+2 << endl;
}
void solve(){
cin >> X >> Y >> K;
if(X == Y) {cout << 0 << endl; return;}
if(K == 1) {cout << abs(X-Y) << endl; return;}
if(X > Y) swap(X, Y);
if(X + 1 == Y) {cout << 1 << endl; return;}
if((X ^ Y) <= K) {cout << 1 << endl; return;}
ll tmpK = K + 1;
if((tmpK & (-tmpK)) == tmpK)
{
solve1();
}
else
{
solve2();
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int t;cin>>t;
while(t--)
solve();
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3704kb
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
Time Limit Exceeded
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 ...