QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#485658 | #8325. 重塑时光 | Williamxzh | 100 ✓ | 924ms | 6816kb | C++20 | 2.5kb | 2024-07-20 22:43:10 | 2024-07-20 22:43:12 |
Judging History
answer
#include <bits/stdc++.h>
#define il inline
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
il ll qp(ll a,ll b){
ll ans=1ll;
while(b){
if(b&1) ans=(ans*a)%mod;
a=(a*a)%mod,b>>=1;
}return ans;
}
il void add(int &x,int y){x=(x+y>=mod?x+y-mod:x+y);}
il void del(int &x,int y){x=(x<y?x-y+mod:x-y);}
const int N=16;
int n,m,k,S,e[N][N],pc[1<<N],to[1<<N],lg[1<<N],a[N],h[1<<N],g[1<<N][N],f[1<<N],ans,fac[50],inv[50],G[1<<N];
int F[N],b[N],c[N];
il int ck(int x,int y){//check whether if y doesnt has some edge to x
return (to[y]&x)==0;
}
il void init(){
int x,y,z,u,v,w;
for(int i=2;i<S;++i) lg[i]=lg[i>>1]+1;
for(int i=1;i<S;++i) pc[i]=pc[i-(i&-i)]+1;
for(int i=0;i<n;++i) for(int j=0;j<n;++j) if(e[i][j]) a[i]|=(1<<j);
for(int i=1;i<S;++i) to[i]=to[i-(i&-i)],x=lg[i&-i],to[i]|=a[x];
fac[0]=1ll;for(int i=1;i<=n*2;++i) fac[i]=(1ll*fac[i-1]*i)%mod;
inv[n*2]=qp(fac[n*2],mod-2ll);for(int i=n*2-1;i>=0;--i) inv[i]=(1ll*inv[i+1]*(i+1ll))%mod;
}
il ll calc(ll X){
ll x,y,z,u,v,w,ret=0;
x=1ll;for(int s=0;s<S;++s) G[s]=f[s]=0;
for(int i=1;i<=n;++i){
x=(x*X)%mod;
for(int s=0;s<S;++s){
y=(g[s][i]*x)%mod;if(!(i&1)) y=mod-y;
add(G[s],y);
}
}
f[0]=1ll;
for(int s=1;s<S;++s)
for(int t=s;t;t=(t-1)&s) if(ck(t,s^t)&&f[s^t]&&G[t]) f[s]=(f[s]+1ll*f[s^t]*G[t])%mod;
return f[S-1];
}
il void solve(){
ll x,y,z,u,v,w;
F[0]=1ll;
for(int i=1;i<=n;++i)
for(int j=i;j>=0;--j) F[j]=((j?F[j-1]:0ll)+1ll*(mod-i)*F[j])%mod;
for(int i=0;i<=n;++i){
x=(1ll*a[i]*inv[i]%mod*inv[n-i])%mod;if((n-i)&1) x=mod-x;
if(!i){for(int j=0;j<=n;++j) b[j]=F[j+1];}
else{
y=qp(1ll*i,mod-2ll),b[0]=mod-1ll*F[0]*y%mod;
for(int j=1;j<=n;++j) b[j]=(1ll*(b[j-1]-F[j]+mod)*y)%mod;
for(int j=n;j;--j) b[j]=b[j-1];b[0]=0;
}
for(int j=0;j<=n;++j) c[j]=(c[j]+1ll*x*b[j])%mod;
}
}
int x,y,z,w;
int main(){
//freopen("P10221_18.in","r",stdin);
scanf("%d%d%d",&n,&m,&k);S=(1<<n);
for(int i=1;i<=m;++i) scanf("%d%d",&x,&y),--x,--y,e[x][y]=1;
init();
h[0]=1ll;
for(int i=1;i<S;++i){
if(i==(i&-i)){h[i]=1ll;continue;}
for(int j=0;j<n;++j){
if(!((i>>j)&1)) continue;
if(ck(i^(1<<j),(1<<j))) add(h[i],h[i^(1<<j)]);
}
}
g[0][0]=1ll;
for(int i=1;i<=n;++i)
for(int s=1;s<S;++s)
for(int t=s;t;t=(t-1)&s)
if(ck(t,s^t)&ck(s^t,t)&((t>>lg[s])&1)) g[s][i]=(g[s][i]+1ll*h[t]*g[s^t][i-1])%mod;
for(int i=1;i<=n;++i) a[i]=calc(1ll*i);a[0]=0;
solve();
for(int i=1;i<=k+1;++i) ans=(ans+1ll*c[i]*inv[k+1-i])%mod;
printf("%lld",1ll*ans*fac[k]%mod*fac[k+1]%mod*inv[n+k]%mod);
return 0;
}
詳細信息
Test #1:
score: 5
Accepted
time: 1ms
memory: 5940kb
input:
3 2 0 1 2 1 3
output:
333333336
result:
ok single line: '333333336'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3904kb
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: 112ms
memory: 4676kb
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: 355ms
memory: 5308kb
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: 235ms
memory: 5316kb
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: 229ms
memory: 5304kb
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: 166ms
memory: 4480kb
input:
13 0 13
output:
1
result:
ok single line: '1'
Test #8:
score: 5
Accepted
time: 161ms
memory: 5296kb
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: 1ms
memory: 3812kb
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: 1ms
memory: 3932kb
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: 54ms
memory: 6016kb
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: 60ms
memory: 4592kb
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: 270ms
memory: 6244kb
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: 181ms
memory: 5228kb
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: 172ms
memory: 5316kb
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: 167ms
memory: 5236kb
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: 293ms
memory: 6188kb
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: 924ms
memory: 6816kb
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: 858ms
memory: 6632kb
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: 823ms
memory: 6684kb
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'