QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#301799#5827. 异或图kkkgjyismine410 1901ms6244kbC++143.9kb2024-01-10 11:56:532024-01-10 11:56:53

Judging History

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

  • [2024-01-10 11:56:53]
  • 评测
  • 测评结果:10
  • 用时:1901ms
  • 内存:6244kb
  • [2024-01-10 11:56:53]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const ll mod=998244353,inv2=499122177;
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],ipw[10005],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);
	}
}
ll mn[1<<20];
void init(int mask){
	if(!mask)return;
	mn[mask]=1e18;
	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,mn[mask]=min(mn[mask],A[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;
	} mn[mask]%=mod;
}
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];
ll dp3[20][1<<15];
int pos1[20],tot1,Id[20],tot2,mn1[1<<15],id4[1<<15];
ll calc(int mask){
   int m=popcnt[mask];
   int nn=N-m;
   tot1=tot2=0;
   for(int i=0;i<N;++i)if((mask>>i)&1)pos1[++tot1]=i+1;else Id[++tot2]=i+1;
   for(int i=0;i<=m;++i)for(int j=0;j<(1<<nn);++j)dp3[i][j]=0;
   for(int i=1;i<(1<<nn);++i) {
   	    mn1[i]=1e9;id4[i]=0;
   	    for(int j=0;j<nn;++j)if((i>>j)&1)mn1[i]=min(mn1[i],Id[j+1]),id4[i]|=(1<<Id[j+1]-1);
   }mn1[0]=1e9;
   dp3[0][0]=1ll;
   for(int i=1;i<=m;++i){
   	    for(int j=0;j<(1<<nn);++j){
   	    	for(int k=j;;k=((k-1)&j)){
   	    		int S=(k^j);
   	    		if(mn1[S]>=pos1[i]&&(popcnt[S]%2==0))dp3[i][j]=(dp3[i][j]+dp3[i-1][k]*dp2[id4[S]|(1<<pos1[i]-1)])%mod;
   	    		if(!k)break;
			}
		}
		if(i==m){
			for(int j=1;j<(1<<nn);++j){
				for(int k=(j&(j-1));;k=((k-1)&j)){
   	    		    int S=(k^j);
   	    		    if(popcnt[S]%2==0)dp3[i][j]=(dp3[i][j]+dp3[i-1][k]*dp2[id4[S]]%mod*(mn[id4[S]]+1ll))%mod;
   	    		    if(!k)break;
			    }
			}
		}
   }
   return dp3[m][(1<<nn)-1]*g[mask]%mod;
}
int main() {
	scanf("%d%d%lld",&N,&M,&C);
	pw[0]=ipw[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,ipw[i]=ipw[i-1]*inv2%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;}if(C==0ll)g[0]=1ll;
    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<<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;
		}
	}
	for(int i=0;i<(1<<N);++i)res=(res+calc(i))%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: 5128kb

input:

4 6 2
7 11 14 0
1 2
1 3
2 3
2 4
4 1
4 3

output:

86

result:

wrong answer 1st numbers differ - expected: '44', found: '86'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 10
Accepted

Test #47:

score: 10
Accepted
time: 1901ms
memory: 6244kb

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: 24ms
memory: 5216kb

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: 3ms
memory: 5100kb

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: 5084kb

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%