QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#529357#6399. Classic: Classical Problemsolar_express#WA 503ms4040kbC++202.3kb2024-08-24 12:29:042024-08-24 12:29:04

Judging History

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

  • [2024-08-24 12:29:04]
  • 评测
  • 测评结果:WA
  • 用时:503ms
  • 内存:4040kb
  • [2024-08-24 12:29:04]
  • 提交

answer

#include<bits/stdc++.h>
#define N 100005
using namespace std;
int T,n,p,a[N];
int id[N],invid[N];
int vis[N];
int gen(){
    for(int i=2;i<p;++i){
        for(int j=0;j<p;++j) vis[j]=0;
        int val=1;
        bool fl=0;
        for(int j=1;j<p;++j){
            if(vis[val]){
                fl=1;
                break;
            }
            vis[val]=1;
            val=1ll*val*i%p;
        }
        if(fl==0) return i;
    }
}
bitset<200000> b,ans,c;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>T;
    while(T--){
        cin>>n>>p;
        int g=gen();
        // cerr<<"g:"<<p<<" "<<g<<endl;
        int val=1;
        for(int i=1;i<=p-1;++i){
            id[val]=i;
            invid[i]=val;
            val=1ll*val*g%p;
        }
        bool fl=0,fl2=0;
        for(int i=1;i<=n;++i){
            cin>>a[i];
            if(a[i]==0) fl=1;
            else fl2=1;
        }
        if(fl==0){
            cout<<"1 1\n";
            cout<<"0\n";
            continue;
        }
        if(fl2==0){
            cout<<p<<" 1\n";
            for(int i=0;i<p;++i)
                cout<<i<<" \n"[i==p-1];
            continue;
        }
        b.reset();
        for(int i=1;i<=n;++i) if(a[i]!=0) b.set((p-1)-id[a[i]]+1),b.set(2*(p-1)-id[a[i]]+1);
        for(int i=1;i<p;++i) ans.set(i);
        fl=0;
        for(int i=1;i<p;++i){
            c=(b>>((p-1)-id[i]))|(b>>(2*(p-1)-id[i]));
            if((c&ans).count()){
                ans=c&ans;
            }else{
                // cout<<"ans ";
                cout<<ans.count()<<" "<<i<<'\n';
                vector<int> a;
                a.clear();
                for(int j=1;j<p;++j)
                    if(ans[j])
                        a.push_back(invid[j]);
                sort(a.begin(),a.end());
                for(auto val:a) cout<<val<<" ";
                cout<<'\n';
                fl=1;
                break;
            }
        }
        if(fl==0){
            cout<<ans.count()<<" "<<p<<'\n';
            vector<int> a;
            a.clear();
            for(int j=1;j<p;++j)
                if(ans[j])
                    a.push_back(invid[j]);
            sort(a.begin(),a.end());
            for(auto val:a) cout<<val<<" ";
            cout<<'\n';
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3776kb

input:

3
2 3
0 2
3 5
2 3 4
3 5
0 2 3

output:

1 2
2 
1 1
0
2 2
2 3 

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

3
1 2
0
1 2
1
2 2
1 0

output:

2 1
0 1
1 1
0
1 2
1 

result:

ok 6 lines

Test #3:

score: 0
Accepted
time: 1ms
memory: 3776kb

input:

7
1 3
0
1 3
1
2 3
1 0
1 3
2
2 3
2 0
2 3
1 2
3 3
0 1 2

output:

3 1
0 1 2
1 1
0
1 2
1 
1 1
0
1 2
2 
1 1
0
2 3
1 2 

result:

ok 14 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 3788kb

input:

31
1 5
0
1 5
1
2 5
1 0
1 5
2
2 5
0 2
2 5
2 1
3 5
1 0 2
1 5
3
2 5
0 3
2 5
1 3
3 5
0 1 3
2 5
3 2
3 5
0 2 3
3 5
2 1 3
4 5
2 0 1 3
1 5
4
2 5
4 0
2 5
1 4
3 5
1 4 0
2 5
2 4
3 5
2 4 0
3 5
4 2 1
4 5
1 0 4 2
2 5
4 3
3 5
0 4 3
3 5
3 1 4
4 5
1 4 3 0
3 5
4 3 2
4 5
2 4 0 3
4 5
2 1 4 3
5 5
1 3 0 2 4

output:

5 1
0 1 2 3 4
1 1
0
1 2
1 
1 1
0
1 2
3 
1 1
0
1 3
1 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
2 2
2 3 
1 1
0
1 4
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
1 3
3 
1 1
0
1 4
3 
1 1
0
1 3
4 
1 1
0
1 4
2 
1 1
0
1 4
4 
1 1
0
4 5
1 2 3 4 

result:

ok 62 lines

Test #5:

score: 0
Accepted
time: 6ms
memory: 3784kb

input:

127
1 7
0
1 7
1
2 7
1 0
1 7
2
2 7
2 0
2 7
2 1
3 7
2 1 0
1 7
3
2 7
3 0
2 7
3 1
3 7
3 1 0
2 7
2 3
3 7
2 0 3
3 7
2 1 3
4 7
2 0 3 1
1 7
4
2 7
0 4
2 7
1 4
3 7
0 1 4
2 7
4 2
3 7
0 4 2
3 7
1 2 4
4 7
2 4 1 0
2 7
4 3
3 7
3 0 4
3 7
3 1 4
4 7
1 0 4 3
3 7
3 2 4
4 7
3 0 2 4
4 7
4 1 3 2
5 7
4 3 0 1 2
1 7
5
2 7
0 ...

output:

7 1
0 1 2 3 4 5 6
1 1
0
1 2
1 
1 1
0
1 2
4 
1 1
0
1 3
1 
1 1
0
1 2
5 
1 1
0
2 2
1 5 
1 1
0
2 2
4 5 
1 1
0
1 4
1 
1 1
0
1 2
2 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
3 3
1 2 4 
1 1
0
2 2
2 5 
1 1
0
1 3
2 
1 1
0
1 3
4 
1 1
0
1 5
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
2 2
3 4 
1 1
0
1 3
1 
1 1
0
1 3
3 
1 1
0
1 ...

result:

ok 254 lines

Test #6:

score: 0
Accepted
time: 96ms
memory: 3732kb

input:

2047
1 11
0
1 11
1
2 11
0 1
1 11
2
2 11
0 2
2 11
2 1
3 11
1 0 2
1 11
3
2 11
3 0
2 11
3 1
3 11
0 3 1
2 11
2 3
3 11
0 2 3
3 11
2 1 3
4 11
1 0 3 2
1 11
4
2 11
0 4
2 11
4 1
3 11
1 4 0
2 11
2 4
3 11
2 0 4
3 11
2 1 4
4 11
0 2 1 4
2 11
3 4
3 11
3 4 0
3 11
3 1 4
4 11
4 1 3 0
3 11
4 3 2
4 11
3 4 0 2
4 11
3 1...

output:

11 1
0 1 2 3 4 5 6 7 8 9 10
1 1
0
1 2
1 
1 1
0
1 2
6 
1 1
0
1 3
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1 1
0
2 2
4 6 
1 1
0
1 4
1 
1 1
0
1 2
3 
1 1
0
2 2
1 3 
1 1
0
1 3
6 
1 1
0
2 3
1 6 
1 1
0
2 2
3 4 
1 1
0
3 2
1 3 4 
1 1
0
1 3
6 
1 1
0
1 5
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
6 9 
1 1
0
1 3
1 
1 1
0
2...

result:

ok 4094 lines

Test #7:

score: 0
Accepted
time: 408ms
memory: 4028kb

input:

8191
1 13
0
1 13
1
2 13
0 1
1 13
2
2 13
2 0
2 13
2 1
3 13
2 1 0
1 13
3
2 13
0 3
2 13
1 3
3 13
1 0 3
2 13
2 3
3 13
2 0 3
3 13
3 1 2
4 13
1 3 2 0
1 13
4
2 13
4 0
2 13
4 1
3 13
0 1 4
2 13
2 4
3 13
0 2 4
3 13
2 4 1
4 13
0 1 4 2
2 13
3 4
3 13
3 0 4
3 13
4 1 3
4 13
4 1 0 3
3 13
4 2 3
4 13
3 2 0 4
4 13
3 4...

output:

13 1
0 1 2 3 4 5 6 7 8 9 10 11 12
1 1
0
1 2
1 
1 1
0
1 2
7 
1 1
0
1 3
1 
1 1
0
1 2
9 
1 1
0
2 2
1 9 
1 1
0
2 2
7 9 
1 1
0
1 4
1 
1 1
0
1 2
10 
1 1
0
2 2
1 10 
1 1
0
1 3
7 
1 1
0
2 3
1 7 
1 1
0
2 2
9 10 
1 1
0
3 2
1 9 10 
1 1
0
1 3
7 
1 1
0
1 5
1 
1 1
0
1 2
8 
1 1
0
2 2
1 8 
1 1
0
2 2
7 8 
1 1
0
1 3
...

result:

ok 16382 lines

Test #8:

score: 0
Accepted
time: 503ms
memory: 4040kb

input:

11764
1 17
0
1 17
1
2 17
0 1
1 17
2
2 17
0 2
2 17
2 1
3 17
2 1 0
1 17
3
2 17
3 0
2 17
1 3
3 17
3 0 1
2 17
2 3
3 17
0 3 2
3 17
3 2 1
4 17
3 2 0 1
1 17
4
2 17
0 4
2 17
4 1
3 17
1 4 0
2 17
4 2
3 17
0 2 4
3 17
2 1 4
4 17
2 4 1 0
2 17
3 4
3 17
3 4 0
3 17
4 1 3
4 17
4 1 0 3
3 17
2 4 3
4 17
2 0 3 4
4 17
2 ...

output:

17 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 1
0
1 2
1 
1 1
0
1 2
9 
1 1
0
1 3
1 
1 1
0
1 2
6 
1 1
0
2 2
1 6 
1 1
0
2 2
6 9 
1 1
0
1 4
1 
1 1
0
1 2
13 
1 1
0
2 2
1 13 
1 1
0
1 3
9 
1 1
0
2 3
1 9 
1 1
0
2 2
6 13 
1 1
0
3 2
1 6 13 
1 1
0
1 3
9 
1 1
0
1 5
1 
1 1
0
1 2
7 
1 1
0
2 2
1 7 
1 1
0
2 2
7 9...

result:

ok 23528 lines

Test #9:

score: 0
Accepted
time: 431ms
memory: 3724kb

input:

10526
1 19
0
1 19
1
2 19
0 1
1 19
2
2 19
2 0
2 19
2 1
3 19
0 2 1
1 19
3
2 19
0 3
2 19
3 1
3 19
1 0 3
2 19
3 2
3 19
2 0 3
3 19
1 3 2
4 19
1 2 0 3
1 19
4
2 19
0 4
2 19
4 1
3 19
0 1 4
2 19
4 2
3 19
4 0 2
3 19
2 4 1
4 19
4 2 0 1
2 19
4 3
3 19
0 3 4
3 19
1 3 4
4 19
3 4 0 1
3 19
4 3 2
4 19
0 4 3 2
4 19
1 ...

output:

19 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
1 1
0
1 2
1 
1 1
0
1 2
10 
1 1
0
1 3
1 
1 1
0
1 2
13 
1 1
0
2 2
1 13 
1 1
0
2 2
10 13 
1 1
0
1 4
1 
1 1
0
1 2
5 
1 1
0
2 2
1 5 
1 1
0
1 3
10 
1 1
0
2 3
1 10 
1 1
0
2 2
5 13 
1 1
0
3 2
1 5 13 
1 1
0
1 3
10 
1 1
0
1 5
1 
1 1
0
1 2
4 
1 1
0
2 2
1 4 
1...

result:

ok 21052 lines

Test #10:

score: -100
Wrong Answer
time: 348ms
memory: 3732kb

input:

10000
9 83
60 35 63 59 58 81 0 13 71
1 5
0
1 7
0
2 61
39 0
2 7
0 4
1 7
0
2 19
0 14
1 2
0
3 23
14 10 0
3 11
0 5 2
1 5
0
2 7
0 4
2 3
0 2
2 3
0 1
1 13
0
5 47
10 2 34 15 0
1 2
0
1 17
0
1 11
0
2 7
1 0
1 7
0
2 23
0 17
2 13
10 0
2 7
1 0
6 31
19 13 6 29 0 24
4 23
0 5 18 17
2 19
0 5
1 7
0
2 13
7 0
3 17
0 6 1...

output:

2 3
38 76 
5 1
0 1 2 3 4
7 1
0 1 2 3 4 5 6
1 2
36 
1 2
2 
7 1
0 1 2 3 4 5 6
1 2
15 
2 1
0 1
2 2
5 7 
2 2
6 9 
5 1
0 1 2 3 4
1 2
2 
1 2
2 
1 2
1 
13 1
0 1 2 3 4 5 6 7 8 9 10 11 12
4 2
18 22 24 33 
2 1
0 1
17 1
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
11 1
0 1 2 3 4 5 6 7 8 9 10
1 2
1 
7 1
0 1 2 3 4 5...

result:

wrong answer 317th lines differ - expected: '1 2', found: '2 2'