QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#212595#5827. 异或图kkkgjyismine420 209ms22020kbC++143.7kb2023-10-13 17:52:482023-10-13 17:52:48

Judging History

This is the latest submission verdict.

  • [2023-10-13 17:52:48]
  • Judged
  • Verdict: 20
  • Time: 209ms
  • Memory: 22020kb
  • [2023-10-13 17:52:48]
  • Submitted

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);
	}
}
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],tr[20],id[1<<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;}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<N;++i)id[(1<<i)]=i;
    for(int i=0;i<N;++i){
    	tr[i]=(1<<i);
    	for(int j=0;j<N;++j)if(cmp(i+1,j+1))tr[i]|=(1<<j);
	}
	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=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;}
		}
    	int Mask=0,mx0=-1,p=0,t1=0;
		for(int j=0;j<N;++j){
			v=getop(i,j);
			if(!v)fl=0;else p|=(1<<j),mx0=j;
			if(v==2)Mask|=(1<<j);
			if(v==1)t1|=(1<<j);
		}
		p^=(1<<mx0);
		for(int S=p;;S=((S-1)&p)){
			if(popcnt[S]&1){
				if(((S|(1<<mx0))|t1)==t1)f[i]=(f[i]+f[i-val3[S|(1<<mx0)]]*dp2[S|(1<<mx0)]%mod*(mn[S|(1<<mx0)]+1ll))%mod;
			}else{
				if(popcnt[((S|(1<<mx0))&Mask)]==1&&(tr[id[((S|(1<<mx0))&Mask)]]&(S|(1<<mx0)))==(S|(1<<mx0)))f[i]=(f[i]+f[i-val3[(S|(1<<mx0))]-pw3[id[((S|(1<<mx0))&Mask)]]]*dp2[(S|(1<<mx0))])%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: 20
Accepted

Test #1:

score: 20
Accepted
time: 0ms
memory: 20244kb

input:

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

output:

44

result:

ok 1 number(s): "44"

Test #2:

score: 0
Accepted
time: 2ms
memory: 18132kb

input:

4 4 6
12 14 14 5
4 2
1 4
3 2
1 2

output:

798

result:

ok 1 number(s): "798"

Test #3:

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

input:

3 3 2
10 4 11
2 1
3 2
1 3

output:

33

result:

ok 1 number(s): "33"

Test #4:

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

input:

4 0 4
9 8 5 2

output:

148

result:

ok 1 number(s): "148"

Test #5:

score: 0
Accepted
time: 2ms
memory: 18224kb

input:

5 6 14
12 15 13 13 12
3 1
2 4
2 5
2 1
5 3
4 5

output:

21337

result:

ok 1 number(s): "21337"

Test #6:

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

input:

4 5 5
5 2 4 13
2 1
3 4
1 4
4 2
3 2

output:

42

result:

ok 1 number(s): "42"

Test #7:

score: 0
Accepted
time: 2ms
memory: 20152kb

input:

4 4 3
13 7 8 12
4 1
3 1
2 4
4 3

output:

552

result:

ok 1 number(s): "552"

Test #8:

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

input:

4 2 12
1 12 4 11
2 1
3 1

output:

70

result:

ok 1 number(s): "70"

Test #9:

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

input:

5 5 6
10 7 8 2 13
1 5
1 3
2 1
4 3
5 3

output:

1231

result:

ok 1 number(s): "1231"

Test #10:

score: 0
Accepted
time: 2ms
memory: 20208kb

input:

5 7 9
6 7 13 15 12
1 3
5 3
5 2
4 5
4 3
4 1
3 2

output:

6223

result:

ok 1 number(s): "6223"

Test #11:

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

input:

3 0 3
15 7 12

output:

104

result:

ok 1 number(s): "104"

Test #12:

score: 0
Accepted
time: 2ms
memory: 20272kb

input:

3 2 9
10 6 5
1 2
1 3

output:

17

result:

ok 1 number(s): "17"

Test #13:

score: 0
Accepted
time: 2ms
memory: 20152kb

input:

5 5 11
7 9 15 9 9
5 4
5 1
5 2
1 3
3 4

output:

5224

result:

ok 1 number(s): "5224"

Test #14:

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

input:

5 0 12
9 8 14 11 2

output:

3006

result:

ok 1 number(s): "3006"

Test #15:

score: 0
Accepted
time: 2ms
memory: 20148kb

input:

3 1 1
6 10 4
3 1

output:

30

result:

ok 1 number(s): "30"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #16:

score: 50
Accepted
time: 6ms
memory: 20244kb

input:

9 27 705410105529944560
929827299070190972 733413770730537329 473007347105710981 190062421504120247 918561152768663129 196040702922254016 981530663192980241 203295856357272834 337150461958783092
2 8
7 9
8 9
2 3
9 2
2 7
9 5
9 4
4 8
1 7
6 3
6 1
4 1
6 5
2 4
2 1
9 3
9 6
7 3
7 5
5 2
4 5
2 6
3 1
3 8
4 3
8 6

output:

5392583

result:

ok 1 number(s): "5392583"

Test #17:

score: 0
Accepted
time: 3ms
memory: 20048kb

input:

9 7 788762650337246371
605340092851479114 625896945107761227 361131331380167081 572133549445050458 929899192003968010 340514051531987427 690728985364969400 268762741220048006 818120252827139346
5 8
9 6
6 1
1 9
9 8
5 1
4 5

output:

35237078

result:

ok 1 number(s): "35237078"

Test #18:

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

input:

7 8 968166787047166534
945734997493219809 465616677643913237 530128109571749460 717120283671096308 118646732725835921 510958884109370001 797022604947155276
5 2
4 7
1 2
6 5
4 2
4 6
1 6
6 3

output:

133871438

result:

ok 1 number(s): "133871438"

Test #19:

score: -50
Wrong Answer
time: 209ms
memory: 22020kb

input:

12 21 341964498832651322
422448536649714733 488538974423366199 893293448611252565 879334133559023407 13516625885288091 43377983230712374 263189254162337644 474056776923289355 540904774976211471 103364876621830299 515157013276720499 213857038587555252
12 9
8 3
1 9
1 7
3 1
8 11
11 10
6 10
6 1
10 2
7 9...

output:

24100754

result:

wrong answer 1st numbers differ - expected: '296076062', found: '24100754'

Subtask #3:

score: 0
Time Limit Exceeded

Test #47:

score: 0
Time Limit Exceeded

input:

14 0 731833687287532167
157552918690640051 900457311668526045 111217720157614956 84140984111060473 814012186135880499 784848789620248379 958953377683017264 105083874298571687 104921429970878846 44983041675142735 871013110538758030 686733907990421995 98063590462078176 495161493555059993

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%