QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#279479#6961. XOR SubsequenceIsaacMoris#AC ✓200ms6420kbC++141.6kb2023-12-08 19:54:022023-12-08 19:54:03

Judging History

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

  • [2023-12-08 19:54:03]
  • 评测
  • 测评结果:AC
  • 用时:200ms
  • 内存:6420kb
  • [2023-12-08 19:54:02]
  • 提交

answer

#include<iostream>
#include <bits/stdc++.h>

#define ld long double
#define ll long long
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int N = 30, mod = 998244353;
int basis[N];

bool add(int mask) {
    for (int i = 0; i < N; i++) {
        if ((mask & 1 << i) == 0)continue;
        if (!basis[i]) {
            basis[i] = mask;
            return true;
        }
        mask ^= basis[i];
    }
    return false;
}

vector<int> query(vector<int> &ans) {
    vector<int> res;
    int n = ans.size();
    for (int mask = 0; mask < (1 << n); mask++) {
        int cur = 0;
        for (int i = 0; i < n; i++) {
            if ((mask & 1 << i) != 0) {
                cur ^= ans[i];
            }
        }
        res.push_back(cur);
    }
    sort(res.begin(), res.end());
    return res;
}

void doWork() {
    memset(basis, 0, sizeof basis);
    int n;
    cin >> n;
    vector<int> a(1 << n, 0);
    for (int i = 1; i < (1 << n); i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    vector<int> ans;
    for (auto i: a) {
        if (add(i)) {
            ans.push_back(i);
        }
    }
    while (ans.size() < n) {
        ans.insert(ans.begin(), 0);
    }
    if (ans.size() > n) {
        cout << -1 << "\n";
        return;
    }

    if (a != query(ans)) {
        cout << "-1\n";
        return;
    }
    for (auto i: ans)cout << i << " ";
    cout << "\n";
}

int main() {
    IO
    int t = 1;
    cin >> t;
    for (int i = 1; i <= t; i++) {
        //  cout << "Case #" << i << ": ";
        doWork();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 200ms
memory: 6420kb

input:

4115
1
220426753
2
75752216 139004411 214624995
3
425320853 659634699 1040767902 61426054 620262285 1033998872 451979283
4
289669156 16842978 272957638 16779852 289737354 21236708 4456872 268501358 285213068 272894568 4524806 21299530 68270 285281058 268438464
5
288507119 704365180 764545802 9869220...

output:

220426753 
75752216 139004411 
61426054 425320853 620262285 
68270 4456872 16779852 268438464 
25699612 34220493 74041718 280650227 678684512 
-1
0 0 0 67108864 134217728 268435456 536870912 
136604 6052763 27897018 37591031 75573769 136661209 279830679 547648454 
2026397 2791316 8827893 17803262 38...

result:

ok 4115 lines