QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#94433#6137. Sub-cycle GraphxuzhihaodedieRE 0ms0kbC++141.5kb2023-04-05 22:50:252023-04-05 22:50:27

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-05 22:50:27]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-04-05 22:50:25]
  • 提交

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();
	}
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

3
4 2
4 3
5 3

output:


result: