QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#844596#8325. 重塑时光IvanZhang2009100 ✓424ms20640kbC++204.3kb2025-01-06 08:42:122025-01-06 08:42:12

Judging History

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

  • [2025-01-06 08:42:12]
  • 评测
  • 测评结果:100
  • 用时:424ms
  • 内存:20640kb
  • [2025-01-06 08:42:12]
  • 提交

answer

/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 */

/*
 * @Description: I want to be the weakest vegetable in the world!
 * @Author: I.Z.
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD         1000000007
#define speMOD      2933256077ll
#define int         long long
#define pii         pair<int,int>
#define all(v)      v.begin(),v.end()
#define pb          push_back
#define REP(i,b,e)  for(int i=(b);i<(int)(e);++i)
#define over(x)     {cout<<(x)<<endl;return;}
#define lowbit(x)   ((x)&(-(x)))
#define cntbit(x)   __builtin_popcount(x)
#define deal(v)     sort(all(v));v.erase(unique(v.begin(),v.end()),v.end())
#define lbound(v,x) lower_bound(all(v),x)-v.begin()
mt19937 sd(random_device{}());
int qpow(int a,int b,int m=MOD,int res=1){
	a%=m;
	while(b>0)res=(b&1)?(res*a%m):(res),a=a*a%m,b>>=1;
	return res;
}
int exgcd(int x,int y,int &a,int &b){
	if(y==0){
		a=1;b=0;
		return x;
	}
	int d=exgcd(y,x%y,a,b);
	int z=b;
	b=a-b*(x/y);
	a=z;
	return d;
}
int _x_,_y_;
inline int inverse(int x,int y=MOD){
	exgcd(x,y,_x_,_y_);
	return (_x_+y)%y;
}
int fac[2000005],inv[2000005];
void init(int n){
	fac[0]=inv[0]=1;
	REP(i,1,n+1)fac[i]=fac[i-1]*i%MOD;
	inv[n]=qpow(fac[n],MOD-2);
	for(int i=n-1;i>=1;--i)inv[i]=inv[i+1]*(i+1)%MOD;
}
int binom(int x,int y){
	return x<y||y<0? 0:fac[x]*inv[y]%MOD*inv[x-y]%MOD;
}
int n,m,k;
int s1[20],s2[20];
int f[100000][20],F[100005];
int g[100000][20];
int S[100005],S1[100005];
int dp[20][20];
void Main() {
	cin>>n>>m>>k;
	dp[0][0]=1;
	REP(i,0,k){
		REP(j,0,n+1)if(dp[i][j]){
			(dp[i+1][j]+=dp[i][j]*(j+2))%=MOD;
			(dp[i+1][j+1]+=dp[i][j]*(n+i+1-j-2))%=MOD;
		}
	}
	REP(i,0,m){
		int x,y;
		cin>>x>>y;
		--x,--y;
		s1[x]|=(1<<y);
		s2[y]|=(1<<x);
	}
	REP(i,1,(1<<n)){
		int x=__builtin_ctz(i);
		S[i]=S[i^(1<<x)]|s1[x]|s2[x];
		S1[i]=S1[i^(1<<x)]|s1[x];
	}
	F[0]=1;
	REP(i,1,(1<<n)){
		REP(j,0,n)if((i>>j)&1){
			if(!(s1[j]&i))F[i]+=F[i^(1<<j)];
		}
		F[i]%=MOD;
	}
	f[0][0]=1;
	REP(i,1,(1<<n)){
		int x=__builtin_ctz(i);
		for(int j=i;j;j=(j-1)&i)if((j>>x)&1){
			if(S[j]&(j^i))continue;
			REP(l,0,cntbit(i)){
				(f[i][l+1]+=f[i^j][l]*F[j])%=MOD;
			}
		}
	}
	g[0][0]=1;
	REP(i,1,(1<<n)){
		for(int j=i;j;j=(j-1)&i)if(!(S1[j]&(i^j))){
			int n1=cntbit(j),n2=cntbit(i)-cntbit(j);
			REP(l,1,n1+1)if(f[j][l]){
				REP(p,0,n2+1)if(g[i^j][p]){
					(g[i][l+p]+=(l&1? 1:-1)*g[i^j][p]*f[j][l])%=MOD;
				}
			}
		}
	}
	init(100);
	int ans=0;
	REP(i,1,n+1)if(g[(1<<n)-1][i]){
		int co=0;
		REP(j,0,i){
			//有几个位置不让选,一共 i-1 个位置
			int c=binom(i-1,j)*fac[i-j+1+k-1]%MOD*inv[i-j]%MOD;
			if(j&1)co-=c;else co+=c;
		}
		co%=MOD;(co*=fac[i])%=MOD;
		(ans+=co*g[(1<<n)-1][i])%=MOD;
	}
	(ans*=inv[k+n])%=MOD;
	(ans+=MOD)%=MOD;
	over(ans)
}
void TC() {
    int tc=1;
	while(tc--){
		Main();
		cout.flush();
	}
}
signed main() {
	return cin.tie(0),cout.tie(0),ios::sync_with_stdio(0),TC(),0;
}
/*
1. CLEAR the arrays (ESPECIALLY multitests)
2. DELETE useless output
 */

详细


Pretests


Final Tests

Test #1:

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

input:

3 2 0
1 2
1 3

output:

333333336

result:

ok single line: '333333336'

Test #2:

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

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: 57ms
memory: 12324kb

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: 187ms
memory: 14772kb

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: 88ms
memory: 14760kb

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: 66ms
memory: 15816kb

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: 88ms
memory: 11828kb

input:

13 0 13

output:

1

result:

ok single line: '1'

Test #8:

score: 5
Accepted
time: 9ms
memory: 14312kb

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: 2ms
memory: 9824kb

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

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

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

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: 93ms
memory: 15760kb

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

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: 13ms
memory: 14164kb

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: 10ms
memory: 14824kb

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: 136ms
memory: 14584kb

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: 424ms
memory: 19972kb

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: 298ms
memory: 19308kb

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: 357ms
memory: 20640kb

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'