QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135150#6637. Perfect StringsPhantomThreshold#ML 0ms0kbC++201.2kb2023-08-05 12:13:122023-08-05 12:13:15

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-05 12:13:15]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-08-05 12:13:12]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;

const int mod = 1e9+7;

int pw(int x,int k)
{
	int re=1;
	for(;k;k>>=1,x=1ll*x*x%mod) if(k&1)
		re=1ll*re*x%mod;
	return re;
}
int inv(int a){return pw(a,mod-2);}

const int maxn = 2e7+10;
int fac[maxn],ifac[maxn];
int C(int n,int m)
{
	if (m<0 || m>n) return 0;
	return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int Catalan(int n){
	return 1LL*fac[2*n]*ifac[n] % mod*ifac[n+1] % mod;	
}

signed main()
{
	ios_base::sync_with_stdio(false);
	
	fac[0]=1; for(int i=1;i<maxn;i++) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[maxn-1]= pw(fac[maxn-1],mod-2);
	for(int i=maxn-2;i>=0;i--) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	
	
	int Tcase; cin>>Tcase;
	while(Tcase--)
	{
		int n,c;
		cin>>n>>c;
		if (c==1){
			cout << 1 << "\n";
			continue;	
		}
		vector<int> pw(n+2);
		int ttt=1LL*c*c % mod *inv(c-1)%mod;
		pw[0]=1;
		for (int i=1;i<=n+1;i++) pw[i]=1LL*pw[i-1]*ttt%mod;
		int ans=0;
		for (int k=0;k<=n;k++){
			int A=1;
			if (k>0) A=(mod-1LL*c*Catalan(k-1)%mod)%mod;
			int B=pw[n-k];
			ans=(ans+1LL*A*B)%mod;
		}
		cout << ans << "\n";
	}
	
	return 0;
}

詳細信息

Test #1:

score: 0
Memory Limit Exceeded

input:

2
3 1
2 2

output:


result: