QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516841 | #9176. Non-Interactive Nim | moosy | WA | 196ms | 3784kb | C++14 | 1.9kb | 2024-08-12 22:20:08 | 2024-08-12 22:20:09 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
void Solve() {
ll n; cin >> n;
// ll n = 2;
vector<ll> a(n + 1);
vector<vector<ll>> b2(100);
ll s;
for(ll i = 1; i <= n; i ++ ) cin >> a[i];
for(ll i = 1; i <= n; i ++ ) {
for(ll j = 1, cnt = 0; j <= a[i]; j *= 2, cnt ++ ) {
if(a[i] & j) {
b2[cnt].push_back(i);
}
}
if(i == 1) s = a[i];
else s ^= a[i];
}
if(s != 0) {
cout << "-1\n"; return ;
}
vector<ll> b;
for(ll i = 64; i >= 0; i -- ) {
if(b2[i].size() == 0) continue;
if(b2[i].size() != 2) {
cout << "-1\n"; return;
}
ll x = b2[i][1], y = b2[i][0];
if(a[x] > a[y]) swap(x, y);
ll z = a[y] - a[y] ^ a[x];
for(ll j = 1, cnt = 0; j <= a[y]; j *= 2, cnt ++ ) {
if(a[y] & j) {
auto new_end = remove(b2[cnt].begin(), b2[cnt].end(), y);
b2[cnt].erase(new_end);
}
}
a[y] ^= a[x];
for(ll j = 1, cnt = 0; j <= a[y]; j *= 2, cnt ++ ) {
if(a[y] & j) {
b2[cnt].push_back(y);
}
}
for(ll j = 1, cnt = 0; j <= a[x]; j *= 2, cnt ++ ) {
if(a[x] & j) {
auto new_end = remove(b2[cnt].begin(), b2[cnt].end(), x);
b2[cnt].erase(new_end);
}
}
a[x] = 0;
b.push_back(y);
b.push_back(z);
}
cout << b.size() / 2 << "\n";
for(ll i = 0; i < b.size(); i ++ ) {
cout << b[i];
if(i % 2 == 0) cout << " ";
else cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
ll T = 1; cin >> T;
while(T -- ) {
Solve();
}
return 0;
}
/*
1
3
1 3 2
2
2 2
3 1
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3520kb
input:
2 4 4 2 7 1 4 1 1 1 1
output:
3 3 4 3 2 4 1 -1
result:
ok OK 1 yes 1 no (2 test cases)
Test #2:
score: 0
Accepted
time: 28ms
memory: 3784kb
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: 0
Accepted
time: 196ms
memory: 3536kb
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 1 89846347117873058 1 1 416235892302498917 1 1 332154513003612985 1 1 43960216631774959 1 1 353215896487285554 1 1 38296945667390613 1 1 209150071115726640 1 1 48610805835417777 1 1 211544111448330513 1 1 25910837432700249 1 1 332285940128117259 1 1 350363936612994860 1 1 243778347549648401 1 1 21...
result:
ok OK 50000 yes 0 no (50000 test cases)
Test #4:
score: 0
Accepted
time: 22ms
memory: 3552kb
input:
33333 3 1 3 2 3 2 3 1 2 1 1 3 1 2 3 3 3 2 1 3 1 2 3 2 1 1 2 3 3 2 3 3 3 1 2 3 3 1 3 2 3 3 2 1 2 2 2 3 3 2 1 2 3 3 3 3 1 2 2 1 1 3 1 2 3 3 1 3 2 3 2 3 1 3 1 3 2 3 1 2 3 3 1 2 3 3 3 1 2 3 2 3 1 3 1 3 2 3 1 3 2 2 1 1 2 3 3 3 3 2 1 2 3 3 3 1 3 2 3 2 3 1 3 2 3 1 3 1 3 2 3 2 3 1 3 2 3 1 3 3 2 1 2 1 1 3 2 ...
output:
2 2 2 1 1 2 2 2 3 1 1 1 1 2 3 2 1 1 2 1 2 3 1 2 3 2 1 1 1 1 1 1 1 3 1 1 3 2 3 2 1 1 2 2 2 1 1 2 1 2 3 1 1 1 2 2 1 2 3 1 1 1 3 2 1 2 2 1 1 1 1 2 3 2 1 1 2 2 2 1 1 2 2 2 3 1 2 2 2 1 1 2 3 2 1 1 2 3 2 1 1 2 1 2 2 1 2 2 2 3 1 2 2 2 1 1 2 2 2 1 1 1 1 1 1 1 3 2 1 2 3 1 1 1 3 2 2 2 1 1 2 2 2 3 1 2 2 2 3 1 ...
result:
ok OK 33333 yes 0 no (33333 test cases)
Test #5:
score: -100
Wrong Answer
time: 25ms
memory: 3616kb
input:
33333 3 1 7 6 3 5 1 4 3 7 3 4 3 6 4 2 3 5 3 6 3 5 3 6 3 7 4 3 3 1 2 3 3 4 3 7 3 2 4 6 3 1 6 7 3 4 5 1 3 1 5 4 2 4 4 2 6 6 3 4 7 3 3 4 2 6 3 1 3 2 3 3 4 7 2 2 2 3 7 3 4 3 2 7 5 3 7 6 1 3 7 3 4 3 4 3 7 3 2 4 6 3 7 1 6 3 3 1 2 3 5 3 6 3 2 6 4 3 6 1 7 3 1 2 3 3 2 1 3 3 5 2 7 3 2 4 6 3 6 3 5 3 5 7 2 2 5 ...
output:
2 2 6 1 1 2 1 4 2 1 2 1 4 2 3 2 1 4 3 2 2 3 5 2 3 2 3 5 2 3 2 1 4 3 3 2 3 2 1 1 2 3 4 2 3 2 3 4 1 2 2 3 6 1 1 2 2 4 3 1 2 2 4 1 1 1 1 4 1 1 6 2 2 4 3 3 2 3 4 2 2 2 2 2 1 1 2 3 4 1 3 1 1 2 2 1 4 2 3 2 2 5 1 2 2 1 6 3 1 2 1 4 2 3 2 3 4 2 3 2 3 4 1 2 2 1 6 2 1 2 1 2 2 1 2 3 5 2 3 2 2 4 1 2 2 3 6 2 1 2 ...
result:
wrong answer game has not ended yet (test case 5)