QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#227114#6795. Everyone Loves Playing Gamesjzh#WA 27ms4000kbC++201.6kb2023-10-26 22:37:472023-10-26 22:37:48

Judging History

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

  • [2023-10-26 22:37:48]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:4000kb
  • [2023-10-26 22:37:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;



struct Base {
    ll d[70];
    Base() {
        for (int i=0; i<=60; i++) d[i] = 0;
    }

    ll& operator[](int i) {return d[i];}

    bool add(ll x) {
        for (int i=60; i>=0; i--) if (x&(1ll<<i)) {
            if (d[i]) {
                x ^= d[i];
            }
            else {
                d[i] = x;
                return true;
            }
        }
        return false;
    }
};



void solve()
{
    int n, m;
    scanf("%d%d", &n, &m);
    vector<ll> orig_a(n);
    vector<ll> orig_b(m);
    Base base_a, base_b;
    
    ll X = 0;
    for (ll i=0, x, y; i<n; i++) {
        scanf("%lld%lld", &x, &y);
        orig_a[i] = x^y;
        X ^= x;
        base_a.add(orig_a[i]);
    }
    for (ll i=0, x, y; i<m; i++) {
        scanf("%lld%lld", &x, &y);
        orig_b[i] = x^y;
        X ^= x;
        base_b.add(orig_b[i]);
    }


    for (int i=60; i>=0; i--) {
        if (base_a[i]==0 && base_b[i]==0) {
            continue;
        }
        else if (base_a[i]) {
            if (X&(1ll<<i) == 0) {
                X ^= base_a[i];
            }
        }
        else if (base_b[i]) {
            if (X&(1ll<<i) == 1) {
                X ^= base_b[i];
            }
        }
        else {
            if (X&(1ll<<i) == 1) {
                X ^= (1ll<<i);
            }
            base_a.add(base_a[i]^base_b[i]);
        }
    }

    printf("%lld\n", X);

}



int main()
{
    int ttt;
    scanf("%d", &ttt);
    while (ttt--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3860kb

input:

2
1 1
6 3
4 1
2 2
1 3
4 6
5 4
2 2

output:

2
2

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 4000kb

input:

15
10000 19
393592642880030158 136857754781138651
64253273480262588 14313422237514072
307460297920437500 243820607396725
21817935197991240 483662625803120946
101295580681553439 176530315178675718
299210522568785323 76213955574929634
71280408782239858 46474979272278520
355918902735266055 227582800425...

output:

1045495887985362389
1086355385751152743
489679383205309739
714166234813254622
755042786246368604
849560468314551126
442991440066969275
962050924956127461
914491931299065648
336927318625133499
117469991285044837
804612902921513679
886246201167951267
822168036187849638
32529802480235380

result:

wrong answer 1st lines differ - expected: '2199023255551', found: '1045495887985362389'