QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94433 | #6137. Sub-cycle Graph | xuzhihaodedie | RE | 0ms | 0kb | C++14 | 1.5kb | 2023-04-05 22:50:25 | 2023-04-05 22:50:27 |
Judging History
answer
// Problem: E. Living Sequence
// Contest: Codeforces - Codeforces Round 863 (Div. 3)
// URL: https://codeforces.com/contest/1811/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
const int N=2e5+10;
int fact[N],infact[N];
int pw[2*N];
int f[2*N];
int qpow(int a,int b) {
if(b==0) return 1;
if(b&1) return a*qpow(a,b-1)%mod;
else {
int mul=qpow(a,b/2)%mod;
return mul*mul%mod;
}
}
void init() {
fact[0]=infact[0]=pw[0]=1;
for(int i=1;i<N;i++) {
fact[i]=fact[i-1]*i%mod;
infact[i]=qpow(fact[i],mod-2)%mod;
pw[i]=pw[i-1]*2%mod;
}
for(int i=0;i<2*N;i++) {
f[i]=fact[2*i]*qpow(fact[i],mod-2)%mod*qpow(pw[i],mod-2)%mod;
}
}
int c(int n,int m) {
if(n<m) return 0;
if(n<0||m<0) return 0;
return fact[n]*infact[n-m]%mod*infact[m]%mod;
}
void solve() {
int n,m;
cin>>n>>m;
if(m>n) {
cout<<0<<endl;
return ;
}
if(m==0) {
cout<<1<<endl;
return ;
}
if(m==n) {
if(n<=2) {
cout<<0<<endl;
} else {
cout<<fact[n-1]*qpow(2,mod-2)%mod;
}
return ;
}
int ans=0;
for(int t=0;t<=n-m;t++) {
//if(n-m-t<0) continue;
int res=c(n,t)*c(n-t,2*(n-m-t))%mod*c(m-1,n-m-t-1)%mod;
int ret=f[n-m-t];
ans=(ans+ret*res%mod*fact[max(0ll,2*m+t-n)])%mod;
}
cout<<ans<<endl;
}
signed main() {
int T=1;
init();
cin>>T;
//for(int i=1;i<=10;i++) cout<<f[i]<<endl;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 4 2 4 3 5 3