QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#135156#6637. Perfect StringsPhantomThreshold#WA 301ms159832kbC++201.2kb2023-08-05 12:15:092023-08-05 12:15:14

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:15:14]
  • 评测
  • 测评结果:WA
  • 用时:301ms
  • 内存:159832kb
  • [2023-08-05 12:15:09]
  • 提交

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;
signed 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: 100
Accepted
time: 191ms
memory: 159832kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: -100
Wrong Answer
time: 301ms
memory: 159744kb

input:

100000
1 1
4 1
5 5
3 5
1 2
5 3
1 1
3 3
5 2
2 1
4 1
5 5
2 3
4 1
3 3
2 5
3 2
4 3
4 4
3 5
3 1
5 2
2 2
4 2
5 4
1 2
3 1
4 5
2 5
5 3
1 5
5 2
3 2
5 2
4 1
1 3
3 2
4 5
2 1
4 1
2 2
1 1
3 5
4 5
2 3
3 5
2 5
2 4
5 4
2 3
1 1
2 1
4 4
1 5
5 4
1 3
5 4
4 5
1 3
1 1
3 3
2 4
2 4
2 1
5 5
1 3
2 3
4 1
4 3
2 4
2 4
4 2
1 1
1...

output:

1
1
247070384
203125009
2
468750114
1
875000017
252
1
1
247070384
750000009
1
875000017
312500005
20
437500037
271604966
203125009
1
252
6
70
115226420
2
1
519531276
312500005
468750114
250000003
252
20
252
1
500000005
20
519531276
1
1
6
1
203125009
519531276
750000009
203125009
312500005
111111115
...

result:

wrong answer 3rd numbers differ - expected: '71445', found: '247070384'