QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#513367 | #9176. Non-Interactive Nim | ucup-team3661# | WA | 27ms | 3600kb | C++20 | 1.8kb | 2024-08-10 17:38:46 | 2024-08-10 17:38:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
int T;
cin >> T;
while (T--) {
int N;
cin >> N;
vector<int> A(N);
for (int i = 0; i < N; i++) {
cin >> A[i];
}
if (N >= 201) {
cout << -1 << '\n';
continue;
}
auto valid = [&](ll x, vector<int> a) {
int cnt = 0;
int id = -1;
for (int i = 0; i < N; i++) {
if ((a[i] ^ x) < a[i]) {
cnt++;
id = i;
}
}
if (cnt != 1) return -1;
return id;
};
vector<pair<int, int>> ans;
auto dfs = [&](auto&& dfs, vector<int> a) -> bool {
if (ranges::max(a) == 0) {
return true;
}
for (int i = 0; i < N; i++) {
int b = a[i];
a[i] = 0;
int id = valid(b, a);
// xor(a)=b
if (id != -1) {
int c = a[id];
a[id] = a[id] ^ b;
// xor(a)=0
if (dfs(dfs, a)) {
ans.push_back({i, b});
return true;
}
a[id] = c;
}
a[i] = b;
}
return false;
};
if (!dfs(dfs, A)) {
cout << -1 << '\n';
} else {
assert(ans.size() <= 100);
ranges::reverse(ans);
cout << ans.size() << '\n';
for (auto [a, b] : ans) {
cout << ++a << ' ' << b << '\n';
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3532kb
input:
2 4 4 2 7 1 4 1 1 1 1
output:
3 1 4 2 2 3 1 -1
result:
ok OK 1 yes 1 no (2 test cases)
Test #2:
score: 0
Accepted
time: 27ms
memory: 3600kb
input:
50000 2 3 3 2 2 2 2 3 3 2 2 2 2 3 3 2 3 3 2 1 1 2 1 1 2 1 1 2 2 2 2 2 2 2 3 3 2 2 2 2 1 1 2 3 3 2 1 1 2 1 1 2 1 1 2 3 3 2 1 1 2 1 1 2 3 3 2 2 2 2 3 3 2 3 3 2 2 2 2 1 1 2 3 3 2 2 2 2 2 2 2 3 3 2 3 3 2 1 1 2 1 1 2 1 1 2 3 3 2 3 3 2 1 1 2 1 1 2 3 3 2 2 2 2 2 2 2 2 2 2 1 1 2 1 1 2 2 2 2 2 2 2 1 1 2 3 3 ...
output:
1 1 3 1 1 2 1 1 3 1 1 2 1 1 3 1 1 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 3 1 1 2 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 3 1 1 2 1 1 3 1 1 3 1 1 2 1 1 1 1 1 3 1 1 2 1 1 2 1 1 3 1 1 3 1 1 1 1 1 1 1 1 1 1 1 3 1 1 3 1 1 1 1 1 1 1 1 3 1 1 2 1 1 2 1 1 2 1 1 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 3 1 1 3 ...
result:
ok OK 50000 yes 0 no (50000 test cases)
Test #3:
score: -100
Wrong Answer
time: 5ms
memory: 3572kb
input:
50000 2 89846347117873058 89846347117873058 2 416235892302498917 416235892302498917 2 332154513003612985 332154513003612985 2 43960216631774959 43960216631774959 2 353215896487285554 353215896487285554 2 38296945667390613 38296945667390613 2 209150071115726640 209150071115726640 2 48610805835417777 ...
output:
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
result:
wrong answer judge has answer but participant doesn't (test case 1)