QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#392559 | #8325. 重塑时光 | do_while_true | 45 | 512ms | 21820kb | C++20 | 4.0kb | 2024-04-17 17:20:04 | 2024-04-17 17:20:05 |
Judging History
answer
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<ctime>
#include<random>
#include<array>
#include<assert.h>
// #define int long long
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define dbg(x) cerr<<"In Line "<< __LINE__<<" the "<<#x<<" = "<<x<<'\n'
#define dpi(x,y) cerr<<"In Line "<<__LINE__<<" the "<<#x<<" = "<<x<<" ; "<<"the "<<#y<<" = "<<y<<'\n'
#define DE(fmt,...) fprintf(stderr, "Line %d : " fmt "\n",__LINE__,##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<ll,int>pli;
typedef pair<ll,ll>pll;
typedef pair<int,ll>pil;
typedef vector<int>vi;
typedef vector<ll>vll;
typedef vector<pii>vpii;
typedef vector<pll>vpll;
template<typename T>T cmax(T &x, T y){return x=x>y?x:y;}
template<typename T>T cmin(T &x, T y){return x=x<y?x:y;}
template<typename T>
T &read(T &r){
r=0;bool w=0;char ch=getchar();
while(ch<'0'||ch>'9')w=ch=='-'?1:0,ch=getchar();
while(ch>='0'&&ch<='9')r=r*10+(ch^48),ch=getchar();
return r=w?-r:r;
}
template<typename T1,typename... T2>
void read(T1 &x,T2& ...y){read(x);read(y...);}
const int mod=1000000007;
inline void cadd(int &x,int y){x=(x+y>=mod)?(x+y-mod):(x+y);}
inline void cdel(int &x,int y){x=(x-y<0)?(x-y+mod):(x-y);}
inline int add(int x,int y){return (x+y>=mod)?(x+y-mod):(x+y);}
inline int del(int x,int y){return (x-y<0)?(x-y+mod):(x-y);}
int qpow(int x,int y){
int s=1;
while(y){
if(y&1)s=1ll*s*x%mod;
x=1ll*x*x%mod;
y>>=1;
}
return s;
}
const int N=17;
const int M=(1<<16)+10;
inline int bit(int x){return 1<<x;}
inline int subin(int x,int S){return ((1<<(x-1))&S)>0;}
int n,m,k;
int fac[110],inv[110];
int C(int x,int y){return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;}
int e[N][N];
vi vec;
map<ull,int>vis;
ull Has(vi a){
sort(a.begin(),a.end());
ull s=0;
for(auto i:a)s=s*19260817+i+1;
return s;
}
int kcf[N];
int dp[N][N];
int f[M],fdp[M],fr[N],nx[N];
int frs[M];
int ans=0;
void dfs(int S,int cf){
if((int)vec.size()>k+1)return ;
if(S==0){
int len=vec.size();
ull now=Has(vec);
if(vis[now])return ;
vis[now]=1;
cadd(ans,1ll*fac[len]*kcf[len]%mod*cf%mod);
// dbg(ans);
return ;
}
for(int T=S;T;T=(T-1)&S){
if(frs[T]&(S^T))continue;
vec.pb(T);
dfs(S^T,1ll*cf*f[T]%mod);
vec.pop_back();
}
}
signed main(){
#ifdef do_while_true
// assert(freopen("timeline.in","r",stdin));
// assert(freopen("timline.out","w",stdout));
#endif
n=100;
fac[0]=1;for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%mod;
inv[n]=qpow(fac[n],mod-2);for(int i=n-1;~i;--i)inv[i]=1ll*inv[i+1]*(i+1)%mod;
read(n,m,k);
for(int len=1;len<=n;len++){
memset(dp,0,sizeof(dp));
dp[1][0]=1;
for(int i=1;i<=len;i++){
for(int j=0;j<=k;j++){
cadd(dp[i+1][j+1],1ll*dp[i][j]*(len-i)%mod);
if(j<n)
cadd(dp[i][j+1],1ll*dp[i][j]*(i+j+1)%mod);
}
}
kcf[len]=dp[len][k];
dpi(len,kcf[len]);
}
for(int i=1,u,v;i<=m;i++){
read(u,v);
e[u][v]=1;
}
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(e[i][k]&&e[k][j])
e[i][j]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(e[i][j])
fr[j]|=bit(i-1),nx[i]|=bit(j-1);
for(int i=1;i<bit(n);i++){
frs[i]=frs[i-(i&(-i))]|fr[__lg(i&(-i))+1];
}
f[0]=1;
for(int S=1;S<bit(n);S++){
fdp[0]=1;
vi vec;
for(int T=S;;T=(T-1)&S){
vec.pb(T);
if(T==0)break;
}
reverse(vec.begin(),vec.end());
for(auto T:vec){
for(int i=1;i<=n;i++)if(!subin(i,T)&&subin(i,S)&&!(fr[i]&T))
cadd(fdp[T|bit(i-1)],fdp[T]);
}
f[S]=fdp[S];
for(auto T:vec)fdp[T]=0;
}
dfs(bit(n)-1,1);
int cnt=fac[n];
for(int i=1;i<=k;i++)cnt=1ll*cnt*(n+i)%mod;
dpi(ans,cnt);
ans=1ll*ans*qpow(cnt,mod-2)%mod;
cout<<ans<<'\n';
#ifdef do_while_true
// cerr<<'\n'<<"Time:"<<1.0*clock()/CLOCKS_PER_SEC*1000<<" ms"<<'\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 5
Accepted
time: 0ms
memory: 3816kb
input:
3 2 0 1 2 1 3
output:
333333336
result:
ok single line: '333333336'
Test #2:
score: 5
Accepted
time: 0ms
memory: 3884kb
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: 0
Time Limit Exceeded
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:
result:
Test #4:
score: 0
Time Limit Exceeded
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:
result:
Test #5:
score: 5
Accepted
time: 213ms
memory: 3964kb
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: 0
Time Limit Exceeded
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:
result:
Test #7:
score: 0
Time Limit Exceeded
input:
13 0 13
output:
result:
Test #8:
score: 5
Accepted
time: 204ms
memory: 4360kb
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: 3916kb
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: 10ms
memory: 4088kb
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: 65ms
memory: 4048kb
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: 0
Time Limit Exceeded
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:
result:
Test #13:
score: 0
Time Limit Exceeded
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:
result:
Test #14:
score: 0
Time Limit Exceeded
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:
result:
Test #15:
score: 5
Accepted
time: 395ms
memory: 17840kb
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: 512ms
memory: 21820kb
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: 0
Time Limit Exceeded
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:
result:
Test #18:
score: 0
Time Limit Exceeded
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:
result:
Test #19:
score: 0
Time Limit Exceeded
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:
result:
Test #20:
score: 0
Time Limit Exceeded
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