QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#94465 | #6192. Interval Problem | xuzhihaodedie | WA | 58ms | 8756kb | C++14 | 1.4kb | 2023-04-06 10:50:53 | 2023-04-06 10:50:55 |
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=1e5+10;
int fact[2*N],infact[2*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]=f[0]=1;
for(int i=1;i<2*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=1;i<N;i++) {
f[i]=f[i-1]*(2*i-1)%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<<endl;
}
return ;
}
int ans=0;
for(int t=0;t<=n-m;t++) {
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)%mod;
}
cout<<ans<<endl;
}
signed main() {
int T=1;
init();
cin>>T;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 58ms
memory: 8756kb
input:
5 2 3 6 7 1 9 5 10 4 8
output:
0 0 0 0 0
result:
wrong answer 1st numbers differ - expected: '7', found: '0'