QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#94465#6192. Interval ProblemxuzhihaodedieWA 58ms8756kbC++141.4kb2023-04-06 10:50:532023-04-06 10:50:55

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-06 10:50:55]
  • 评测
  • 测评结果:WA
  • 用时:58ms
  • 内存:8756kb
  • [2023-04-06 10:50:53]
  • 提交

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'