QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#514728 | #9176. Non-Interactive Nim | ucup-team1231# | WA | 0ms | 3880kb | C++14 | 1.6kb | 2024-08-11 08:41:43 | 2024-08-11 08:41:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int n;
LL a[100005], ans[65];
vector<int> hv[65];
vector<pair<int, int> > G[125];
bool vis[125];
LL dfs(int v, int p, int d) {
vis[v] = true;
LL ret = a[v] & (1LL << d);
for(auto u : G[v]) if(u.first != p) {
LL ca = dfs(u.first, v, d);
ret ^= ca;
ans[u.second] ^= ca;
}
return ret;
}
void dmerge(int d) {
for(int i = 0; i < n; i++)
vis[i] = false;
for(int i = 0; i < n; i++)
if(!vis[i] && dfs(i, -1, d)) hv[d].push_back(i);
}
void solve() {
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%lld", &a[i]);
}
if(n > 120) {
printf("-1\n"); return;
}
for(int i = 0; i < n; i++) G[i].clear();
for(int i = 59; i >= 0; i--) {
hv[i].clear();
dmerge(i);
if(hv[i].size() == 0) continue;
if(hv[i].size() == 2) {
int u = hv[i][0], v = hv[i][1];
G[u].push_back(make_pair(v, i));
G[v].push_back(make_pair(u, i));
ans[i] = 1LL << i;
continue;
}
printf("-1\n"); return;
}
vector<pair<int, LL> > ret;
for(int i = 59; i >= 0; i--) if(hv[i].size() == 2) {
int u = hv[i][0], v = hv[i][1];
ret.push_back(make_pair(u, a[u] - (a[u] ^ ans[i])));
a[u] ^= ans[i]; a[v] ^= ans[i];
}
printf("%d\n", (int)ret.size());
for(int i = 0; i < n; i++) printf("%d %lld\n", ret[i].first + 1, ret[i].second);
}
int main() {
int T;
scanf("%d", &T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3880kb
input:
2 4 4 2 7 1 4 1 1 1 1
output:
3 1 1 1 2 1 1 1 0 -1
result:
wrong answer Integer parameter [name=p] equals to 0, violates the range [1, 4] (test case 2)