QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#385615#5827. 异或图grass8cow30 9ms6560kbC++172.2kb2024-04-10 21:43:082024-04-10 21:43:09

Judging History

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

  • [2024-04-10 21:43:09]
  • 评测
  • 测评结果:30
  • 用时:9ms
  • 内存:6560kb
  • [2024-04-10 21:43:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,inv2=(mod+1)/2;
#define ll long long
#define pb push_back 
ll C,p2[70],i2[70];
void ad(ll &x,ll y){(x+=y)%=mod;}
ll cal(vector<ll>e){
	ll X=0;for(ll o:e)X^=o;
	ll su=0;
	for(int i=60;i>=0;i--){
		if(((X^C)>>i)&1)break;
		if(i==0){ad(su,1);continue;}
		ll dp[2]={1,0},ks[2]={0,0};
		ll gz=1;
		for(ll o:e){
			ll gp=((o&((1ll<<(i-1))-1))+1)%mod;
			gz=gz*gp%mod;
			ks[0]=ks[1]=0;
			for(int j=0;j<2;j++)if(dp[j]){
				if((o>>(i-1))&1)
					ad(ks[j],dp[j]*p2[i-1]),ad(ks[j^1],dp[j]*gp);
				else ad(ks[j],dp[j]*gp);
			}
			dp[0]=ks[0],dp[1]=ks[1];
		}
		(su+=(dp[(C>>(i-1))&1]-((((X^C)>>(i-1))&1)?0:gz))*i2[i-1])%=mod;
	}
	return su;
}
int n,m;
int fi[1<<15],pp[1<<15];
ll a[15],dp[1<<15][17],zp[1<<15];
int ts[20];
int jk(int l,int r){
	if(l>r)return 0;
	return ((1<<(r-l+1))-1)<<l;
}
int ct[1<<15];
bool A[15][15];
int be[15],rk[15]; 
int main(){
	p2[0]=i2[0]=1;
	for(int i=1;i<=60;i++)p2[i]=2*p2[i-1]%mod,i2[i]=i2[i-1]*inv2%mod;
	scanf("%d%d%lld",&n,&m,&C);
	for(int i=0;i<n;i++)scanf("%lld",&a[i]),be[i]=i;
	sort(be,be+n,[&](int x,int y){return a[x]<a[y];});
	sort(a,a+n);
	for(int i=0;i<n;i++)rk[be[i]]=i;
	for(int i=0,u,v;i<m;i++)scanf("%d%d",&u,&v),u=rk[u-1],v=rk[v-1],A[u][v]=A[v][u]=1;
	for(int s=0;s<(1<<n);s++){
		for(int i=0;i<n;i++)if((s>>i)&1)for(int j=i+1;j<n;j++)if((s>>j)&1)if(A[i][j])ct[s]++;
		for(int i=0;i<=n;i++)if(!((s>>i)&1)){fi[s]=i;break;}
		if(s)pp[s]=pp[s>>1]+(s&1);
	}
	zp[0]=1;
	for(int s=1;s<(1<<n);s++){
		zp[s]=(ct[s]?0:1);int x=(s&-s);
		for(int s2=s&(s-1);s2;s2=(s2-1)&s)if(s2&x){
			if(ct[s^s2])continue;
			ad(zp[s],-zp[s2]);
		}
	}
	for(int i=0;i<=n;i++)ts[i]=((1<<(n-i))-1)<<i;
	dp[0][0]=1;
	for(int i=0;i<n;i++)for(int s=0;s<(1<<n);s++)if(dp[s][i]){
		int S=ts[i];
		S^=(S&s);
		for(int s2=S;s2;s2=(s2-1)&S)if((s2>>i)&1){
			int j=fi[((1<<i)-1)|s2|s],s_=s|s2;
			s_^=(s_&jk(i,j-1));
			if(pp[s2]&1)ad(dp[s_|(1<<i)][j],dp[s][i]*zp[s2]);
			else ad(dp[s_][j],dp[s][i]*zp[s2]%mod*((a[i]+1)%mod));
		}
	}
	ll ans=0;
	for(int s=0;s<(1<<n);s++)if(dp[s][n]){
		vector<ll>X;for(int i=0;i<n;i++)if((s>>i)&1)X.pb(a[i]);
		ad(ans,dp[s][n]*cal(X));
	}
	return printf("%lld",ans),0;
}

詳細信息

Subtask #1:

score: 20
Accepted

Test #1:

score: 20
Accepted
time: 1ms
memory: 3888kb

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: 0ms
memory: 4120kb

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

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

input:

4 0 4
9 8 5 2

output:

148

result:

ok 1 number(s): "148"

Test #5:

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

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: 1ms
memory: 3820kb

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: 1ms
memory: 3772kb

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

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: 1ms
memory: 3796kb

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: 1ms
memory: 3888kb

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

input:

3 0 3
15 7 12

output:

104

result:

ok 1 number(s): "104"

Test #12:

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

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: 0ms
memory: 3908kb

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: 1ms
memory: 3832kb

input:

5 0 12
9 8 14 11 2

output:

3006

result:

ok 1 number(s): "3006"

Test #15:

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

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: 1ms
memory: 3896kb

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: 0ms
memory: 3912kb

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: 1ms
memory: 3844kb

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: 0
Accepted
time: 3ms
memory: 4456kb

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:

296076062

result:

ok 1 number(s): "296076062"

Test #20:

score: -50
Wrong Answer
time: 2ms
memory: 4084kb

input:

11 42 215284372701527433
670445786006000260 969876209382224733 248721347029697734 375741447316879814 840434941395805804 187091598433077755 126574401069916039 764298539206353847 750906714570719526 387387869969339518 713140316419888823
1 10
2 5
1 7
4 11
3 11
2 7
4 5
9 5
1 6
3 4
10 9
11 9
3 7
2 1
8 11
...

output:

-137125763

result:

wrong answer 1st numbers differ - expected: '861118590', found: '-137125763'

Subtask #3:

score: 10
Accepted

Test #47:

score: 10
Accepted
time: 9ms
memory: 6560kb

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: 1ms
memory: 4388kb

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: 1ms
memory: 3892kb

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: 1ms
memory: 4272kb

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:

100%
Accepted

Dependency #2:

0%