QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#848648#8325. 重塑时光Fesdrer100 ✓426ms52120kbC++173.0kb2025-01-09 00:23:222025-01-09 00:23:23

Judging History

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

  • [2025-01-09 00:23:23]
  • 评测
  • 测评结果:100
  • 用时:426ms
  • 内存:52120kb
  • [2025-01-09 00:23:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=15,P=1e9+7;
int n,m,k,h[1<<N],g[1<<N][N+2],f[1<<N],nowg[1<<N],in[N],out[N];
vector<int> spd[1<<N],aspd[1<<N];
inline int fadd(int x,int y){
	return (x+y>=P?x+y-P:x+y);
}
inline int fminus(int x,int y){
	return (x>=y?x-y:x+P-y);
}
inline int get(int x,int y){
	int ret=0;
	for(int i=0,mul=1;i<n;i++,mul*=3){
		if(x&(1<<i))	ret+=mul;
		if(y&(1<<i))	ret+=mul*2;
	}
	return ret;
}
inline void getp(){
	for(int s=0;s<(1<<n);s++){
		int now=0;
		for(int i=0;i<n;i++) if(s&(1<<i))	now|=(1<<i),now|=out[i];
		now=(1<<n)-1-now;
		for(int t=now;t;t=(t-1)&now)	spd[s|t].push_back(t);
		now=(1<<n)-1-now;
		for(int i=0;i<n;i++) if(s&(1<<i))	now|=in[i];
		now=(1<<n)-1-now;
		for(int t=now;t;t=(t-1)&now)	aspd[s|t].push_back(t);
	}
	// for(int s=0;s<(1<<n);s++)	cout<<aspd[s].size()<<endl;
}
inline void geth(){
	h[0]=1;
	for(int s=1;s<(1<<n);s++){
		for(int i=0;i<n;i++) if((s&(1<<i))&&!((s-(1<<i))&in[i]))
			h[s]=fadd(h[s],h[s-(1<<i)]);
		// cout<<h[s]<<endl;
	}
}
inline void getg(){
	g[0][0]=1;
	for(int s=1;s<(1<<n);s++){
		int mx=0;
		for(int i=0;i<n;i++) if(s&(1<<i))	mx=i;
		for(int t:aspd[s])	if((t&(1<<mx)))	for(int i=1;i<=n;i++)
			g[s][i]=fadd(g[s][i],1ll*g[s-t][i-1]*h[t]%P);
		// cout<<g[s][1]<<endl;
		// for(int t:aspd[s])	cout<<s<<" "<<t<<endl;
	}
}
inline int getf(int x){
	for(int s=0;s<(1<<n);s++){
		nowg[s]=0;
		for(int i=0,mul=1;i<=n;i++,mul=1ll*mul*x%P){
			if(i&1)	nowg[s]=fadd(nowg[s],1ll*g[s][i]*mul%P);
			else	nowg[s]=fminus(nowg[s],1ll*g[s][i]*mul%P);
		}
	}
	f[0]=1;
	for(int s=1;s<(1<<n);s++){
		f[s]=0;
		// cout<<spd[s].size()<<endl;
		// for(int t:spd[s])	cout<<s<<" "<<t<<endl;
		for(int t:spd[s]){
			f[s]=fadd(f[s],1ll*f[s-t]*nowg[t]%P);
			// cout<<s<<" "<<t<<" "<<f[s-t]<<" "<<nowg[t]<<" "<<f[s]<<endl;
		}
	}
	// cout<<"-"<<endl;
	return f[(1<<n)-1];
}
inline int solve(){
	auto inv=[&](const int aaa){
		int aa=aaa,nn=P-2,ret=1;
		for(;nn;nn>>=1,aa=1ll*aa*aa%P)	if(nn&1)	ret=1ll*ret*aa%P;
		return ret;
	};
	vector<int> y(0),sum(n+1,0),now(0);
	for(int i=0;i<=n;i++)	y.push_back(getf(i));
	// for(int i:y)	cout<<i<<" ";
	// cout<<endl;
	for(int i=0;i<=n;i++){
		int nowk=y[i];
		for(int j=0;j<=n;j++) if(j!=i)	nowk=1ll*nowk*inv(fminus(i,j))%P;
		now.clear(),now.push_back(nowk);
		for(int j=0;j<=n;j++) if(j!=i){
			now.push_back(0);
			for(int t=int(now.size())-1;t>0;t--)
				now[t]=fminus(now[t],1ll*j*now[t-1]%P);
		}
		for(int j=0;j<=n;j++)	sum[j]=fadd(sum[j],now[j]);
	}
	reverse(sum.begin(),sum.end());
	int ans=0;
	for(int i=1,mul=k+1;i<=min(n,k+1);i++,mul=1ll*mul*(k-i+2)%P)
		ans=fadd(ans,1ll*sum[i]*mul%P);
	for(int i=1;i<=k;i++)	ans=1ll*ans*i%P;
	for(int i=1;i<=n+k;i++)	ans=1ll*ans*inv(i)%P;
	return ans;
}
int main(){
	// freopen("P10221_18.in","r",stdin);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m>>k;
	for(int i=1,x,y;i<=m;i++){
		cin>>x>>y;x--,y--;
		out[x]|=(1<<y),in[y]|=(1<<x);
	}
	getp();
	geth();
	getg();
	cout<<solve()<<endl;
	return 0;
}

詳細信息


Pretests


Final Tests

Test #1:

score: 5
Accepted
time: 0ms
memory: 7240kb

input:

3 2 0
1 2
1 3

output:

333333336

result:

ok single line: '333333336'

Test #2:

score: 5
Accepted
time: 1ms
memory: 6892kb

input:

5 7 5
1 4
2 3
1 2
4 5
2 5
2 4
1 5

output:

895039689

result:

ok single line: '895039689'

Test #3:

score: 5
Accepted
time: 62ms
memory: 12472kb

input:

13 12 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13

output:

76923078

result:

ok single line: '76923078'

Test #4:

score: 5
Accepted
time: 177ms
memory: 27072kb

input:

14 13 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14

output:

535714290

result:

ok single line: '535714290'

Test #5:

score: 5
Accepted
time: 103ms
memory: 17712kb

input:

14 13 0
2 9
1 2
1 3
3 8
6 11
2 7
1 5
5 12
2 13
3 14
3 10
3 6
2 4

output:

700595243

result:

ok single line: '700595243'

Test #6:

score: 5
Accepted
time: 80ms
memory: 15144kb

input:

14 13 14
9 11
2 9
5 10
4 6
10 13
2 3
2 7
4 12
2 4
3 8
7 14
3 5
1 2

output:

465070080

result:

ok single line: '465070080'

Test #7:

score: 5
Accepted
time: 95ms
memory: 20020kb

input:

13 0 13

output:

1

result:

ok single line: '1'

Test #8:

score: 5
Accepted
time: 29ms
memory: 7916kb

input:

14 91 14
3 4
2 10
3 10
1 13
6 8
5 6
10 13
7 8
4 9
4 7
3 7
13 14
2 12
1 3
6 9
9 14
1 10
2 9
7 11
9 11
3 12
8 10
4 13
5 9
11 12
5 14
8 12
8 13
5 13
1 5
6 11
9 13
2 5
1 14
7 14
4 14
3 5
5 11
6 12
1 2
7 10
1 4
1 8
6 10
3 8
6 13
10 14
7 12
10 11
2 13
8 11
11 13
6 7
10 12
3 14
4 5
1 6
2 14
5 10
8 14
4 8
1...

output:

4362623

result:

ok single line: '4362623'

Test #9:

score: 5
Accepted
time: 0ms
memory: 7044kb

input:

9 15 9
1 2
3 5
2 8
4 8
1 4
2 5
2 7
4 5
1 9
6 8
6 9
1 3
3 7
5 9
5 8

output:

426526937

result:

ok single line: '426526937'

Test #10:

score: 5
Accepted
time: 2ms
memory: 7316kb

input:

9 14 9
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
4 5
6 8
4 7
6 7
3 8
4 6

output:

214820829

result:

ok single line: '214820829'

Test #11:

score: 5
Accepted
time: 14ms
memory: 6904kb

input:

13 68 0
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
2 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
5 6
5 7
5 8
5 9
5 10
5 11
5 12
5 13
6 7
6 8
6 9
6 10
6 11
6 12
6 13
7 8
7 10
7 11
7 12
7 13
8 13
9 10
9 11
9 12
9 13...

output:

65784302

result:

ok single line: '65784302'

Test #12:

score: 5
Accepted
time: 20ms
memory: 8488kb

input:

13 39 13
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
3 4
3 5
3 6
3 7
3 8
3 9
3 10
3 11
3 12
3 13
4 8
4 9
4 10
4 12
4 13
5 6
5 7
5 10
5 11
5 13
6 7
6 11
6 13
8 9
8 12
8 13
11 13

output:

361557272

result:

ok single line: '361557272'

Test #13:

score: 5
Accepted
time: 113ms
memory: 21232kb

input:

14 11 14
2 13
4 11
4 14
5 14
6 9
6 14
7 11
9 14
10 12
10 14
12 14

output:

696132576

result:

ok single line: '696132576'

Test #14:

score: 5
Accepted
time: 46ms
memory: 10672kb

input:

14 46 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 9
2 10
2 11
2 13
2 14
3 4
3 6
3 10
3 11
3 12
3 13
3 14
4 6
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 9
5 11
5 13
5 14
7 8
7 9
7 14
10 11
10 13
10 14
11 13
11 14
13 14

output:

258614192

result:

ok single line: '258614192'

Test #15:

score: 5
Accepted
time: 34ms
memory: 8580kb

input:

14 70 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 4
2 5
2 7
2 8
2 9
2 10
2 11
2 12
2 13
2 14
3 11
3 13
3 14
4 5
4 7
4 8
4 10
4 11
4 12
4 13
4 14
5 7
5 8
5 10
5 12
5 13
5 14
6 7
6 8
6 9
6 10
6 11
6 12
6 13
6 14
7 8
7 10
7 12
7 13
7 14
8 10
8 12
8 13
8 14
9 11
9 12
9 13
9 14
10 1...

output:

209616080

result:

ok single line: '209616080'

Test #16:

score: 5
Accepted
time: 35ms
memory: 8484kb

input:

14 69 14
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
2 3
2 5
2 6
2 7
2 9
2 10
2 11
2 12
2 13
2 14
3 5
3 6
3 7
3 9
3 10
3 11
3 12
3 13
3 14
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
5 6
5 7
5 9
5 10
5 11
5 12
5 13
5 14
6 7
6 9
6 10
6 11
6 12
6 13
6 14
7 9
7 10
7 11
7 12
7 13
7 14
8 12
8 13
8 14
9 10
...

output:

701202127

result:

ok single line: '701202127'

Test #17:

score: 5
Accepted
time: 152ms
memory: 24372kb

input:

14 15 14
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
4 6
5 9

output:

263013541

result:

ok single line: '263013541'

Test #18:

score: 5
Accepted
time: 426ms
memory: 52120kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
3 13
3 15
13 15

output:

963180835

result:

ok single line: '963180835'

Test #19:

score: 5
Accepted
time: 370ms
memory: 51012kb

input:

15 17 15
1 2
1 3
1 4
1 5
1 6
1 7
1 12
1 15
7 12
7 15
8 15
9 15
10 15
11 15
12 15
13 15
14 15

output:

722208430

result:

ok single line: '722208430'

Test #20:

score: 5
Accepted
time: 385ms
memory: 52064kb

input:

15 16 15
1 2
1 3
1 10
2 10
3 10
4 5
4 6
4 7
4 8
4 9
4 10
4 11
4 12
4 13
4 14
4 15

output:

560801339

result:

ok single line: '560801339'