QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205807#6637. Perfect StringsGeospiza#WA 184ms160176kbC++141.0kb2023-10-07 17:28:012023-10-07 17:28:02

Judging History

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

  • [2023-10-07 17:28:02]
  • 评测
  • 测评结果:WA
  • 用时:184ms
  • 内存:160176kb
  • [2023-10-07 17:28:01]
  • 提交

answer

#include <bits/stdc++.h>
#define ll int
#define LL long long
#define Ma 20000005
#define mod 1000000007
#define N 1005
#define pb push_back
#define ls p<<1
#define rs p<<1|1
using namespace std;
ll mul[Ma],pre[Ma];
ll n,k;
ll po(ll p,ll x=mod-2)
{
	ll sum=1;
	while (x)
	{
		if (x&1) sum=1ll*sum*p%mod;
		p=1ll*p*p%mod;
		x>>=1;
	}
	return sum;
}

void pri()
{
	mul[0]=1;
	for (ll i=1;i<Ma;i++)
		mul[i]=1ll*mul[i-1]*i%mod;
	pre[Ma-1]=po(mul[Ma-1]);
	for (ll i=Ma-2;i>=0;i--)
		pre[i]=1ll*pre[i+1]*(i+1)%mod;
	return;
}

ll C(ll x,ll y)
{
	if (x<0||y<0||x>y) return 0;
	return 1ll*mul[y]*pre[x]%mod*pre[y-x]%mod;
}



void sol()
{
	cin>>n>>k;
	if (k==1)
	{
		printf("1\n");
		return;
	}
	ll ans=0,l=1,r=po(k-1,n),inv=po(k-1);
	for (ll i=1;i<=n;i++)
	{
		l=1ll*l*k%mod;
		r=1ll*r*inv%mod;
		ans=(ans+1ll*l*r%mod*C((i-1)*2,(n-1)*2)%mod)%mod;
	}
	printf("%d\n",ans);
}

int main()
{
	pri();
	ios::sync_with_stdio(0); cin.tie(0);
	ll tt;
	cin>>tt;
	while (tt--)
		sol();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 173ms
memory: 160176kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: -100
Wrong Answer
time: 184ms
memory: 160068kb

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
259205
805
2
14403
1
147
1154
1
1
259205
15
1
147
45
34
1455
5404
805
1
1154
6
198
75268
2
1
14445
45
14403
5
1154
34
1154
1
3
34
14445
1
1
6
1
805
14445
15
805
45
28
75268
15
1
1
5404
5
75268
3
75268
14445
3
1
147
28
28
1
259205
3
15
1
1455
28
28
198
1
1
259205
15
5404
3
1
2
15
147
5404
75268
2...

result:

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