QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#515746 | #9176. Non-Interactive Nim | yzy_21 | WA | 21ms | 3540kb | C++14 | 2.1kb | 2024-08-11 23:01:36 | 2024-08-11 23:01:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n;cin >> n;
vector<vector<int>> a(100, vector<int> ());
if(n == 2) {
int x;
for(int i = 1; i <= 2; ++i) {
cin >> x;
}
cout << 1 << " " << x << "\n";
return ;
}
for(int i = 1;i <= n; i++){
int x;cin >> x;
bitset<100> bt(x);
for(int j = 0;j < 100; j++){
if(bt[j]) a[j].push_back(i);
}
}
int f=1;
vector<int> ans1, ans2;
for(int i = 0; i < 100; i++){
int xi = -1;
f = 1;
for(int j = 0; j < 70; j++){
if(a[j].size() > 0){
f = 0;
if(a[j].size() == 2){
xi = j;
break;
}
}
}
if(f==1) break;
if(xi==-1){
cout<<"-1\n";
return;
}
int x=a[xi][0], y=a[xi][1];
int an=0;
for(int j=0;j<70;j++){
int fx=-1,fy=-1;
for(int k=0;k<a[j].size();k++){
if(a[j][k]==x){
fx=k;
}
if(a[j][k]==y){
fy=k;
}
}
if(fx!=-1&&fy!=-1){
if(fx>fy){
a[j].erase(a[j].begin()+fx);
a[j].erase(a[j].begin()+fy);
}
else{
a[j].erase(a[j].begin()+fy);
a[j].erase(a[j].begin()+fx);
}
an+=(1<<j);
}
}
ans1.push_back(an);
ans2.push_back(x);
}
if(f==0){
cout<<"-1\n";
return;
}
cout<<ans1.size()<<"\n";
for(int i=0;i<ans1.size();i++){
cout<<ans2[i]<<" "<<ans1[i]<<"\n";
}
return;
}
signed main()
{
#if !LOCAL
ios::sync_with_stdio(0);
cin.tie(0);
#endif
int tt = 1;
cin >> tt;
while (tt--)
solve();
#if LOCAL
system("pause");
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3528kb
input:
2 4 4 2 7 1 4 1 1 1 1
output:
3 3 1 2 2 1 4 -1
result:
ok OK 1 yes 1 no (2 test cases)
Test #2:
score: -100
Wrong Answer
time: 21ms
memory: 3540kb
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 3 1 2 1 3 1 2 1 3 1 3 1 1 1 1 1 1 1 2 1 2 1 3 1 2 1 1 1 3 1 1 1 1 1 1 1 3 1 1 1 1 1 3 1 2 1 3 1 3 1 2 1 1 1 3 1 2 1 2 1 3 1 3 1 1 1 1 1 1 1 3 1 3 1 1 1 1 1 3 1 2 1 2 1 2 1 1 1 1 1 2 1 2 1 1 1 3 1 3 1 1 1 2 1 3 1 1 1 2 1 2 1 1 1 3 1 1 1 2 1 2 1 2 1 3 1 1 1 3 1 1 1 1 1 2 1 3 1 3 1 2 1 1 1 2 1 3 1 2 ...
result:
wrong answer Integer parameter [name=p] equals to 3, violates the range [1, 2] (test case 1)