QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#515747#9176. Non-Interactive NimEZGGWA 144ms3604kbC++232.0kb2024-08-11 23:01:402024-08-11 23:01:41

Judging History

你现在查看的是最新测评结果

  • [2024-08-11 23:01:41]
  • 评测
  • 测评结果:WA
  • 用时:144ms
  • 内存:3604kb
  • [2024-08-11 23:01:40]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int unsigned long long



void solve()
{
    int n;
    vector<int> a[100];
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        bitset<66> bt(x);
        for(int j=0;j<66;j++){
            if(bt[j]){
                a[j].push_back(i);
            }
        }
    }
    int f=1;
    vector<int> ans1;
    vector<int>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: 3596kb

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: 0
Accepted
time: 29ms
memory: 3604kb

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: 144ms
memory: 3592kb

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 18446744072997763688
1
1 18446744072589414587
1
1 314284030
1
1 18446744071716355204
1
1 18446744071764194094
1
1 18446744071612713843
1
1 18446744072375815185
1
1 918387702
1
1 18446744072168382288
1
1 18446744073531185949
1
1 1439561304
1
1 18446744073252998480
1
1 18446744071914584366
1
1 176...

result:

wrong output format Expected integer, but "18446744072997763688" found (test case 1)