QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#347672 | #8325. 重塑时光 | Crysfly# | 100 ✓ | 800ms | 12996kb | C++17 | 3.9kb | 2024-03-09 14:46:51 | 2024-07-04 03:27:53 |
Judging History
answer
// what is matter? never mind.
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int unsigned long long
#define ull unsigned long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define mod 1000000007
struct modint{
int x;
modint(int o=0){x=o;}
modint &operator = (int o){return x=o,*this;}
modint &operator +=(modint o){return x=x+o.x>=mod?x+o.x-mod:x+o.x,*this;}
modint &operator -=(modint o){return x=x-o.x<0?x-o.x+mod:x-o.x,*this;}
modint &operator *=(modint o){return x=1ll*x*o.x%mod,*this;}
modint &operator ^=(int b){
modint a=*this,c=1;
for(;b;b>>=1,a*=a)if(b&1)c*=a;
return x=c.x,*this;
}
modint &operator /=(modint o){return *this *=o^=mod-2;}
friend modint operator +(modint a,modint b){return a+=b;}
friend modint operator -(modint a,modint b){return a-=b;}
friend modint operator *(modint a,modint b){return a*=b;}
friend modint operator /(modint a,modint b){return a/=b;}
friend modint operator ^(modint a,int b){return a^=b;}
friend bool operator ==(modint a,modint b){return a.x==b.x;}
friend bool operator !=(modint a,modint b){return a.x!=b.x;}
bool operator ! () {return !x;}
modint operator - () {return x?mod-x:0;}
bool operator <(const modint&b)const{return x<b.x;}
};
inline modint qpow(modint x,int y){return x^y;}
vector<modint> fac,ifac,iv;
inline void initC(int n)
{
if(iv.empty())fac=ifac=iv=vector<modint>(2,1);
int m=iv.size(); ++n;
if(m>=n)return;
iv.resize(n),fac.resize(n),ifac.resize(n);
For(i,m,n-1){
iv[i]=iv[mod%i]*(mod-mod/i);
fac[i]=fac[i-1]*i,ifac[i]=ifac[i-1]*iv[i];
}
}
inline modint C(int n,int m){
if(m<0||n<m)return 0;
return initC(n),fac[n]*ifac[m]*ifac[n-m];
}
inline modint sign(int n){return (n&1)?(mod-1):(1);}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 200005
#define inf 0x3f3f3f3f
int n,m,k;
int e[17],es[1<<16];
modint f[1<<16]; // topo orders
modint g[1<<16][17],h[1<<16][17];
bool no(int s,int t){
// no s->t
return (es[s]&t)==0;
}
modint Cdown(int n,int m){
return fac[n]*ifac[n-m];
}
void work()
{
n=read(),m=read(),k=read();
For(i,1,m){
int u=read(),v=read();
--u,--v;
e[u]|=(1<<v);
}
For(i,1,(1<<n)-1){
int t=__lg(i&-i);
es[i]=es[i^(1<<t)]|e[t];
}
// For(i,0,(1<<n)-1) cout<<es[i]<<" "; cout<<" es\n";
f[0]=1;
For(s,0,(1<<n)-1)
For(i,0,n-1)
if(!(s>>i&1) && no((1<<i),s)) f[s|(1<<i)]+=f[s];
// For(s,0,(1<<n)-1) cout<<f[s].x<<" "; cout<<" f\n";
g[0][0]=1;
h[0][0]=1;
For(s,1,(1<<n)-1){
int u=__lg(s&-s);
int c=__builtin_popcount(s);
for(int t=s;t;t=(t-1)&s){
if(t>>u&1){
if(no(t,s^t) && no(s^t,t)){
For(i,1,c) g[s][i]+=g[s^t][i-1]*f[t];
}
}
}
for(int t=s;t;t=(t-1)&s){
if(no(s^t,t)){
For(i,1,c)
For(j,1,i){
if(j&1) h[s][i]+=g[t][j]*h[s^t][i-j];
else h[s][i]-=g[t][j]*h[s^t][i-j];
}
}
}
}
// For(s,0,(1<<n)-1) For(i,0,n) if(g[i][s].x) cout<<"g "<<i<<" "<<s<<" "<<g[i][s].x<<"\n";
// For(s,0,(1<<n)-1) For(i,0,n) if(h[i][s].x) cout<<"h "<<i<<" "<<s<<" "<<h[i][s].x<<"\n";
initC(n+k+50);
modint res=0;
For(i,1,n){
// cout<<"hi "<<i<<" "<<h[i][(1<<n)-1].x<<"\n";
modint coe=0;
For(j,0,i-1)coe+=C(i-1,j)*sign(j)*Cdown(i-j+k,k);
res+=coe*fac[i]*h[(1<<n)-1][i];
}
res*=ifac[n+k];
cout<<res.x<<"\n";
}
signed main()
{
int T=1;
while(T--)work();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 12692kb
input:
3 2 0 1 2 1 3
output:
333333336
result:
ok single line: '333333336'
Test #2:
score: 5
Accepted
time: 2ms
memory: 12720kb
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: 94ms
memory: 12564kb
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: 332ms
memory: 12996kb
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: 144ms
memory: 12624kb
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: 107ms
memory: 12628kb
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: 156ms
memory: 12596kb
input:
13 0 13
output:
1
result:
ok single line: '1'
Test #8:
score: 5
Accepted
time: 16ms
memory: 12760kb
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: 12724kb
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: 0ms
memory: 12540kb
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: 11ms
memory: 12588kb
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: 18ms
memory: 12468kb
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: 184ms
memory: 12888kb
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: 40ms
memory: 12624kb
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: 29ms
memory: 12544kb
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: 28ms
memory: 12604kb
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: 253ms
memory: 12628kb
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: 800ms
memory: 12692kb
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: 661ms
memory: 12880kb
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: 691ms
memory: 12676kb
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'