QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#518958 | #9176. Non-Interactive Nim | Decade | WA | 1ms | 6500kb | C++17 | 3.0kb | 2024-08-14 14:45:52 | 2024-08-14 14:45:57 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
typedef long long ull;
typedef unsigned long long uull;
typedef pair<int, int> PII;
typedef pair<int,PII> PIII;
typedef __int128 lll;
mt19937 rnd1(random_device{}());
mt19937_64 rnd2(random_device{}());
// uniform_int_depthtribution<int> deptht1(0,2e18); //定义deptht1为0——100的随机整数
// uniform_real_depthtribution<double> deptht2(-10,10); //定义deptht2为-10——10的随机浮点数
//#define mp make_pair
//fflush(stdout);
inline void print(__int128 x){//输出模板
if(x<0){
putchar('-');
x=-x;
}
if(x>9) print(x/10);
putchar(x%10+'0');
}
inline int read()
{
int X = 0;
bool flag = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
flag = 0;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
X = (X << 1) + (X << 3) + ch - '0';
ch = getchar();
}
if (flag)
return X;
return ~(X - 1);
}
const ull mod = 998244353,INF = 2e18;
ull qpow(ull a, ull b)
{
ull res = 1;
a %= mod;
assert(b >= 0);
for (; b; b >>= 1)
{
if (b & 1)
res = res * a % mod;
a = a * a % mod;
}
return res;
}
inline int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
const int N = 100010,M = 200100;
int a[N],a1[N];
bool vis[N];
vector<PII> e[N];
vector<int> u,v,x;
void dfs(int u,int k)
{
if(vis[u]) return;
vis[u] = 1;
for(auto [v,t]:e[u])
{
if((v>>k)&1)
{
a[u] ^= (1ll<<k);
a[v] ^= (1ll<<k);
x[t] ^= (1ll<<k);
dfs(v,k);
}
}
}
void solve()
{
int n;
cin>>n;
v.clear(),u.clear(),x.clear();
for(int i=1;i<=n;i++) cin>>a[i],a1[i] = a[i];
for(int i=1;i<=n;i++) e[i].clear();
for(int i=59;i>=0;i--)
{
vector<int> p;
for(int j=1;j<=n;j++) vis[j] = 0;
for(int j=1;j<=n;j++)
{
if(vis[j]) continue;
dfs(j,i);
if((a[j]>>i)&1) p.push_back(j);
}
if(p.size()>2)
{
cout<<-1<<'\n';
return;
}
if(p.size()==2)
{
u.push_back(p[0]);
v.push_back(p[1]);
x.push_back(1ll<<i);
int t = u.size()-1;
e[p[0]].push_back({p[1],t});
e[p[1]].push_back({p[0],t});
}
}
cout<<u.size()<<'\n';
for(int i=0;i<u.size();i++)
{
cout<<u[i]<<' '<<a1[u[i]]-(a1[u[i]]^x[i])<<'\n';
a1[v[i]] ^= x[i];
a1[u[i]] ^= x[i];
}
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin>>t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 6500kb
input:
2 4 4 2 7 1 4 1 1 1 1
output:
3 1 2 1 1 2 1 -1
result:
wrong answer opponent has more than one possible optimal move (test case 1)