QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322745#5827. 异或图275307894a20 28ms4320kbC++142.7kb2024-02-07 16:37:062024-02-07 16:37:07

Judging History

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

  • [2024-02-07 16:37:07]
  • 评测
  • 测评结果:20
  • 用时:28ms
  • 内存:4320kb
  • [2024-02-07 16:37:06]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=3e2+5,M=(1<<15)+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
}using namespace Debug;
int n,m,pl[N],e[N][N];
ll C,A[N],B[N];
ll w[M],es[M],f[N],pw[N],iw[N];
ll calc(int x){
	ll tot=0;
	for(int i=60;~i;i--){
		ll t=1;int op=0;
		static ll f[2],g[2];
		Me(f,0);f[0]=1;
		for(int j=1;j<=n;j++) if(x>>j-1&1){
			t=(B[j]&(1ll<<i)-1)%mod*t%mod;
			if(B[j]>>i&1){
				op^=1;
				Mc(g,f);ll w1=pw[i],w2=(B[j]&(1ll<<i)-1)%mod;
				f[0]=(g[0]*w1+g[1]*w2)%mod;
				f[1]=(g[0]*w2+g[1]*w1)%mod;
			}else{
				ll w=(B[j]&(1ll<<i)-1)%mod;
				f[0]=f[0]*w%mod;f[1]=f[1]*w%mod;
			}
		}
		if(op^(C>>i&1)){tot+=f[C>>i&1]*iw[i]%mod;break;}
		tot+=(f[op]-t)*iw[i]%mod;
	}
	return (tot%mod+mod)%mod;
}
void Solve(){
	int i,j,h;scanf("%d%d%lld",&n,&m,&C);
	for(i=1;i<=n;i++) scanf("%lld",&A[i]),A[i]++;
	iota(B+1,B+n+1,1);sort(B+1,B+n+1,[](int x,int y){return A[x]<A[y];});
	for(i=1;i<=n;i++) pl[B[i]]=i,B[i]=A[B[i]];
	while(m--){
		int x,y;scanf("%d%d",&x,&y);
		x=pl[x];y=pl[y];
		e[x][y]=e[y][x]=1;
	}
	for(i=0;i<(1<<n);i++){
		es[i]=1;for(j=1;j<=n;j++) if(i>>j-1&1) for(h=1;h<=n;h++) if(i>>h-1&1&&e[j][h]) es[i]=0;
		w[i]=es[i];
		for(j=i&(i-1);j;j=(j-1)&i) if((j&-j)==(i&-i)) w[i]-=w[j]*es[i^j];
		w[i]=(w[i]%mod+mod)%mod;
		// gdb(i,w[i]);
	}
	f[(1<<n)-1]=1;
	for(i=1;i<=n;i++){
		for(j=0;j<(1<<n);j++) if(j>>i-1&1&&f[j]){
			int p=(j>>i)<<i;
			for(h=p;h;h=(h-1)&p){
				if(__builtin_parity(h)) f[j^h^(1<<i-1)]=(f[j^h^(1<<i-1)]+f[j]*w[h|(1<<i-1)]%mod*B[i]%mod)%mod;
				else f[j^h]=(f[j^h]+f[j]*w[h|(1<<i-1)])%mod;
			}
		}
	}
	for(pw[0]=iw[0]=i=1;i<=60;i++) pw[i]=pw[i-1]*2%mod,iw[i]=iw[i-1]*(mod+1)/2%mod;
	ll tot=0;for(i=0;i<(1<<n);i++) if(f[i]) tot+=calc(i)*f[i]%mod/*,gdb(i,f[i],calc(i))*/;
	printf("%lld\n",tot%mod);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 20
Accepted

Test #1:

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

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

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

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

input:

4 0 4
9 8 5 2

output:

148

result:

ok 1 number(s): "148"

Test #5:

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

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

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

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

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

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

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

input:

3 0 3
15 7 12

output:

104

result:

ok 1 number(s): "104"

Test #12:

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

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

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

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

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: 0
Wrong Answer
time: 0ms
memory: 4076kb

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:

-815617420

result:

wrong answer 1st numbers differ - expected: '5392583', found: '-815617420'

Subtask #3:

score: 0
Wrong Answer

Test #47:

score: 0
Wrong Answer
time: 28ms
memory: 4320kb

input:

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

output:

629090547

result:

wrong answer 1st numbers differ - expected: '231790380', found: '629090547'

Subtask #4:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%