QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#322365 | #5827. 异或图 | C1942huangjiaxu | 0 | 4ms | 4248kb | C++14 | 1.6kb | 2024-02-06 22:13:10 | 2024-02-06 22:13:11 |
answer
#include<bits/stdc++.h>
using namespace std;
const int P=998244353;
typedef long long ll;
int n,m,p[15],e[1<<15],w[1<<15],ct[1<<15],f[1<<15],g[1<<15],ans,tp,st[15];
ll a[15],b[15],c;
inline void Add(int &x,int y){
if((x+=y)>=P)x-=P;
}
bool cmp(int x,int y){
return a[x]<a[y];
}
int calc(){
ll sa=0;
for(int i=0;i<tp;++i)sa^=a[st[i]];
int res=(sa==c);
for(int i=59;~i;--i){
int S=0;
for(int j=0;j<tp;++j)if(a[st[j]]>>i&1)S|=1<<j;
for(int T=0;T<S;++T)if((T&S)==T&&(ct[T]&1)==(c>>i&1)){
for(int j=0;j<tp;++j)b[j]=(T>>j&1)?(a[st[j]]&(1ll<<i)-1):(1ll<<i)-1;
sort(b,b+tp);
int o=1;
for(int j=0;j<tp-1;++j)o=(b[j]+1)%P*o%P;
Add(res,o);
}
if((ct[S]&1)!=(c>>i&1))break;
}
return res;
}
int main(){
scanf("%d%d%lld",&n,&m,&c);
for(int i=0;i<n;++i)scanf("%lld",&a[i]),p[i]=i;
sort(p,p+n,cmp);
for(int i=1,x,y;i<=m;++i){
scanf("%d%d",&x,&y);
--x,--y;
for(int S=0;S<1<<n;++S)if((S>>x&1)&&(S>>y&1))++e[S];
}
for(int S=1;S<1<<n;++S){
w[S]=!e[S],ct[S]=ct[S>>1]+(S&1);
int U=S^(S&-S);
for(int T=U;T;T=(T-1)&U)Add(w[S],P-(!e[T])*w[S^T]);
}
f[(1<<n)-1]=1;
for(int i=0,x,U=(1<<n)-1;i<n;++i){
x=p[i],U^=1<<x;
for(int S=0;S<1<<n;++S)g[S]=f[S],f[S]*=!(S>>x&1);
for(int S=0;S<1<<n;++S)if((S>>x&1)&&g[S])
for(int T=U&S;;T=(T-1)&U&S){
if(ct[T]&1)Add(f[S^T^(1<<x)],(a[x]+1)%P*w[T|(1<<x)]%P*g[S]%P);
else Add(f[S^T],1ll*w[T|(1<<x)]*g[S]%P);
if(!T)break;
}
}
for(int S=0;S<(1<<n);++S)if(f[S]){
tp=0;
for(int i=0;i<n;++i)if(S>>i&1)st[tp++]=i;
ans=(ans+1ll*f[S]*calc())%P;
}
printf("%d\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3940kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
442
result:
wrong answer 1st numbers differ - expected: '44', found: '442'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #47:
score: 0
Wrong Answer
time: 4ms
memory: 4248kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
911551470
result:
wrong answer 1st numbers differ - expected: '231790380', found: '911551470'
Subtask #4:
score: 0
Skipped
Dependency #1:
0%