QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#610871 | #7679. Master of Both IV | ANIG# | TL | 3ms | 3816kb | C++14 | 1.7kb | 2024-10-04 17:51:06 | 2024-10-04 17:51:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mods=998244353,N=2e3+5,M=(1<<10);
int pows(int a,int b){
if(b==0)return 1;
int res=pows(a,b>>1);
res=res*res%mods;
if(b&1)res=res*a%mods;
return res;
}
const int inv2=pows(2,mods-2);
int t,n,p[N],sm[N],jc[N],ny[N],f[N],pw[N],cnt[N],g[N],dp[N][2];
void XOR(int *p,int n,int op){
for(int mid=1;mid<n;mid<<=1){
for(int i=0;i<n;i+=mid<<1){
for(int j=0;j<mid;j++){
int x=p[i+j],y=p[i+j+mid];
p[i+j]=(x+y)%mods,p[i+j+mid]=(x-y)%mods;
}
}
}
if(op!=1)for(int i=0;i<n;i++)p[i]=p[i]*pows(n,mods-2)%mods;
}
bool ok(int x){
for(int i=1;i<=n;i++)if(sm[i])if(cnt[i&x]&1)return 0;
return 1;
}
bool ok(int x,int y){
for(int i=1;i<=n;i++)if(sm[i]&&y%i==0&&y!=i)if(cnt[i&x]&1)return 0;
return 1;
}
int C(int a,int b){
return jc[a]*ny[b]%mods*ny[a-b]%mods;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
jc[0]=ny[0]=1;pw[0]=1;
for(int i=1;i<N;i++)jc[i]=jc[i-1]*i%mods,ny[i]=pows(jc[i],mods-2),pw[i]=pw[i-1]*2%mods,cnt[i]=cnt[i&-i^i]+1;
cin>>t;
while(t--){
for(int i=1;i<=n;i++)sm[i]=0;
int res=0;
cin>>n;
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++)cin>>p[i],sm[p[i]]++;
for(int i=0;i<M;i++){
if(ok(i))f[i]=pw[n];
}
for(int i=1;i<=n;i++){
if(!sm[i])continue;
memset(g,0,sizeof(g));
int sms=0;
for(int j=1;j<i;j++)if(i%j==0)sms+=sm[j];
for(int j=0;j<M;j++){
if(ok(j,i))g[j]=pw[sms];
}
XOR(g,M,inv2);
// cout<<i<<" "<<g[0]<<endl;
res+=g[0]*pw[sm[i]-1]%mods;
}
XOR(f,M,inv2);
res+=f[0];
cout<<(res%mods-1+mods)%mods<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3816kb
input:
2 3 1 2 3 5 3 3 5 1 1
output:
4 11
result:
ok 2 number(s): "4 11"
Test #2:
score: -100
Time Limit Exceeded
input:
40000 5 4 2 5 5 5 5 5 5 5 5 4 5 1 4 4 4 2 5 2 5 2 4 1 5 3 2 4 5 3 5 1 5 5 3 4 5 5 5 5 4 3 5 4 3 3 5 1 5 4 5 5 2 1 5 2 5 4 2 5 5 3 4 3 4 3 5 5 3 5 1 3 5 5 1 2 4 4 5 4 2 5 1 5 5 5 4 2 5 4 5 5 2 5 2 4 5 1 4 5 4 5 5 4 2 3 2 3 5 1 4 1 3 5 5 1 1 2 1 5 5 5 2 5 1 3 5 3 1 2 5 3 5 5 5 1 1 5 5 2 2 2 1 3 5 3 1 ...