QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#212536 | #5827. 异或图 | kkkgjyismine4 | 10 | 559ms | 51532kb | C++14 | 3.7kb | 2023-10-13 17:00:27 | 2023-10-13 17:00:28 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=998244353;
int N,M,mp[20][20],cnt[1<<20],Lian[1<<20],fa[20];
ll f[15000000],A[20],g[1<<20],C,pw[10003],U[10],V[10],comb[404][404],dp1[1<<20],dp2[1<<20];int p[20],tot,popcnt[1<<20];
int find(int r){return r==fa[r]?r:(fa[r]=find(fa[r]));}
void add(ll &x,const ll y){if((x+=y)>=mod)x-=mod;}
void sub(ll &x,const ll y){if((x+=(mod-y))>=mod)x-=mod;}
void dfs(int u,int mask,int now,int w,int op,int cnt1,ll v,ll &res){
if(u==tot){if((popcnt[now]&1)==op){if(cnt1)res=(res+v*pw[(cnt1-1)*w])%mod;else if(w==0)add(res,v);}return;}
if(!((mask>>u)&1)){
if(w)v=v*(((A[p[u]]&((1ll<<w)-1ll))+1ll)%mod)%mod;
dfs(u+1,mask,now,w,op,cnt1,v,res);
}else{
dfs(u+1,mask,now,w,op,cnt1+1,v,res);
if(w)v=v*(((A[p[u]]&((1ll<<w)-1ll))+1ll)%mod)%mod;
dfs(u+1,mask,(now|(1<<u)),w,op,cnt1,v,res);
}
}
void init(int mask){
if(!mask)return;
for(int i=0;i<N;++i)fa[i]=i;
for(int i=0;i<N;++i)if((mask>>i)&1)for(int j=i+1;j<N;++j)if(((mask>>j)&1)&&mp[i+1][j+1])fa[find(i)]=find(j),++cnt[mask];
int pos=-1;for(int i=0;i<N;++i)if((mask>>i)&1)pos=i;Lian[mask]=1;
for(int i=0;i<N;++i)if(((mask>>i)&1)&&find(i)!=find(pos))Lian[mask]=0;
tot=0;for(int i=0;i<N;++i)if((mask>>i)&1)p[tot++]=i+1;
for(int i=60;i>=0;--i){
int m=0,Xor,cnt1;for(int j=0;j<tot;++j)m|=(((A[p[j]]>>i)&1ll)<<j);
dfs(0,m,0,i,((C>>i)&1ll),0,1ll,g[mask]);
if((popcnt[m]&1)!=((C>>i)&1ll))break;
}// cout<<mask<<" "<<g[mask]<<endl;
}
int pw3[20];
int getop(int x,int y){return ((x/pw3[y])%3);}
bool cmp(int x,int y){
if(A[x]==A[y])return x<y;
return A[x]<A[y];
}
int val3[1<<20];
vector<int>ins[20];
int main() {
scanf("%d%d%lld",&N,&M,&C);pw[0]=pw3[0]=1;for(int i=1;i<=N;++i)pw3[i]=pw3[i-1]*3;for(int i=1;i<=10000;++i)pw[i]=pw[i-1]*2ll%mod;
for(int i=0;i<=400;++i)comb[i][0]=1ll;for(int i=1;i<=400;++i)for(int j=1;j<=i;++j)comb[i][j]=(comb[i-1][j-1]+comb[i-1][j])%mod;
for(int i=0;i<(1<<N);++i)for(int j=0;j<N;++j)if((i>>j)&1)val3[i]+=pw3[j];
for(int i=1;i<(1<<N);++i)popcnt[i]=popcnt[i>>1]+(i&1);for(int i=1;i<=N;++i)scanf("%lld",&A[i]);
for(int i=1;i<=M;++i){int u,v;scanf("%d%d",&u,&v);mp[u][v]=mp[v][u]=1;U[i]=u,V[i]=v;}
for(int i=0;i<(1<<N);++i)init(i);int mx=0;for(int i=0;i<N;++i)mx+=2*pw3[i];ll res=0ll,res1=0ll;f[0]=1ll;
for(int i=0;i<(1<<M);++i){
for(int j=1;j<=N;++j)fa[j]=j,ins[j].clear();int op=0;
for(int j=0;j<M;++j)if((i>>j)&1)fa[find(U[j+1])]=find(V[j+1]),op^=1;
for(int j=1;j<=N;++j)ins[find(j)].push_back(j);int m=0;
for(int j=1;j<=N;++j)
if(ins[j].size()){
sort(ins[j].begin(),ins[j].end(),cmp);
m|=(1<<ins[j][0]-1);
}
if(op)sub(res1,g[m]);else add(res1,g[m]);
}//cout<<res1<<endl;
for(int i=0;i<(1<<N);++i){
if(!i)continue;
int mn=-1;for(int j=0;j<N;++j)if((i>>j)&1){mn=j;break;}
int All=(i^(1<<mn));
for(int k=0;k<=cnt[i];++k){
if(k&1)sub(dp1[i],comb[cnt[i]][k]);
else add(dp1[i],comb[cnt[i]][k]);
}dp2[i]=dp1[i];
for(int j=All;;j=((j-1)&All)){
int now=(j^(1<<mn)),Other=(i^now);
if(now&&Other)dp2[i]=(dp2[i]+(mod-dp2[now])*dp1[Other])%mod;
if(!j)break;
}
if(dp2[i]!=0&&!Lian[i])assert(0);
}
for(int i=1;i<=mx;++i){
int pos=-1,t=i,v,fl=1;
for(int j=0;j<N;++j){
v=getop(i,j);
if(v==2){pos=j;t-=2*pw3[j];break;}
}
if(pos==-1)continue;
int Could=0,Mask=0;
for(int j=0;j<N;++j){
v=getop(i,j);
if(!v)fl=0;
if(v==2)Mask|=(1<<j);
if(v==1&&cmp(pos+1,j+1))Could|=(1<<j);
}
for(int S=Could;;S=((S-1)&Could)){
if(Lian[S|(1<<pos)])f[i]=(f[i]+f[t-val3[S]]*dp2[S|(1<<pos)])%mod;
if(!S)break;
}
if(fl)res=(res+f[i]*g[Mask])%mod;
} cout<<res<<endl;
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: 18004kb
input:
4 6 2 7 11 14 0 1 2 1 3 2 3 2 4 4 1 4 3
output:
51
result:
wrong answer 1st numbers differ - expected: '44', found: '51'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 10
Accepted
Test #47:
score: 10
Accepted
time: 559ms
memory: 51532kb
input:
14 0 731833687287532167 157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993
output:
231790380
result:
ok 1 number(s): "231790380"
Test #48:
score: 0
Accepted
time: 17ms
memory: 14804kb
input:
11 0 101435837408688522 638776638580507479 933944392115323974 19098604312360490 142362319980029593 419910251764515410 275591812677260089 770239593400917018 928344484461634421 67340905784404712 378109786925249078 110881245457449811
output:
242383534
result:
ok 1 number(s): "242383534"
Test #49:
score: 0
Accepted
time: 0ms
memory: 15900kb
input:
9 0 100988561775675251 622570387572403506 684352103903274038 784649864569409753 270298495621205212 56183537059869110 346856482529145989 86639702870530669 607198038565138736 14747634008501988
output:
20893166
result:
ok 1 number(s): "20893166"
Test #50:
score: 0
Accepted
time: 8ms
memory: 15944kb
input:
10 0 839910859917247463 611237879350518457 292219463776059962 548211857317940894 822255554598388425 335628456629874391 774414280870858683 882480367082748768 654587410087321403 74330774886125511 22894883233341926
output:
61697734
result:
ok 1 number(s): "61697734"
Subtask #4:
score: 0
Skipped
Dependency #1:
0%