QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#715685 | #6961. XOR Subsequence | hejinming983282# | AC ✓ | 96ms | 5776kb | C++23 | 1.7kb | 2024-11-06 13:01:49 | 2024-11-06 13:01:50 |
Judging History
answer
// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);
#define maxn 300005
using namespace std;
inline int read() {
int now = 0, nev = 1; char c = getchar();
while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
return now * nev;
}
void write(int x) {
if(x < 0) putchar('-'), x = -x;
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int n, a[maxn];
bool ok;
void work() {
int i, k = 1, j = 1ll << 30;
for( ; j; j >>= 1) {
for(i = k; i <= n; i++)
if(a[i] & j) break ;
if(i > n) continue ;
swap(a[i], a[k]);
for(i = 1; i <= n; i++)
if(i != k && a[i] & j) a[i] ^= a[k];
k++;
}
k--;
if(k != n) ok = 1;
else ok = 0;
n = k;
}
signed main() {
quickio
quickin
quickout
int T = read();
while(T--) {
n = read(); int sum = 0;
int tmp = (1ll << n) - 1;
swap(n, tmp);
for(int i = 1; i <= n; i++)
a[i] = read(), sum ^= a[i];
if(n == 1) {
write(a[1]), putchar(10);
continue ;
}
if(sum != 0) {
write(-1), putchar(10);
continue ;
}
work();
while(tmp > n) write(0), putchar(' '), tmp--;
for(int i = n; i >= 1; i--)
write(a[i]), putchar(' ');
putchar(10);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 96ms
memory: 5776kb
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 381...
result:
ok 4115 lines