QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#356148#6510. Best Carry Player 3x_jw#WA 0ms3584kbC++141.6kb2024-03-17 16:07:032024-03-17 16:07:05

Judging History

你现在查看的是最新测评结果

  • [2024-03-17 16:07:05]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3584kb
  • [2024-03-17 16:07:03]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
using ll=long long;
using db=double;
using pii=pair<int,int>;
#define pb push_back
#define endl "\n"
/*
5
41 18467 6334
7
26500 19169 15724
1
11478 29358 26962
1
24464 5705 28145
1
23281 16827 9961
1
*/
void solve()
{
    ll x, y, k;
    cin>>x>>y>>k;
    //x=rand(), y=rand(), k=rand();
    if((!k) || k==1) {cout<<abs(x-y)<<endl;return ;}
    ll tmp = x^y;
    if(tmp<=k){
        cout<<"1\n";
        return;
    }
    bitset<70>xx(x), yy(y), kk(k);
    int m = 69;
    while(m>=0 && kk[m]==0) m--;
    m++;
    ll d=(y>>m)-(x>>m), ans=0;
    if(d>0){//x<y
        //先变全1
        ll m1=(1ll<<m)-1;
        ll sub=m1^(m1&x);
        if(!sub);
        else if(sub<=k) ans++;
        else if(sub>k) ans+=2;
        ans++, d--;
        ll bs=0;
        if(k==m1) bs=2;
        else bs=3;
        ans+=bs*d;
        x=0;
    }
    else if(d<0){
        //先全变0
        ll m1=(1ll<<m)-1;
        ll sub=m1&x;
        if(!sub);
        else if(sub<=k) ans++;
        else if(sub>k) ans+=2;
        ans++, d++;
        ll bs=0;
        if(k==m1) bs=2;
        else bs=3;
        ans-=bs*d;
        x=m1;
    }
    //printf("%lld===\n", ans);
    ll m1=(1ll<<m)-1;
    y = y&m1, x = x&m1;
    ll cost=x^y;
    if(!cost);
    else if(cost<=k) ans++;
    else if(cost>k) ans+=2;
    cout<<min( ans, abs(x-y)) <<endl;
}

signed main()
{
    #ifdef ONLINE_JUDGE
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    #endif
    int _=1;
    cin>>_;
    while(_--) solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3584kb

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
0
3
4
0
6
128
1152921504606846975

result:

wrong answer 2nd numbers differ - expected: '2', found: '0'