QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#206047#6637. Perfect StringsGeospizaWA 206ms160112kbC++141.0kb2023-10-07 18:16:362023-10-07 18:16:37

Judging History

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

  • [2023-10-07 18:16:37]
  • 评测
  • 测评结果:WA
  • 用时:206ms
  • 内存:160112kb
  • [2023-10-07 18:16:36]
  • 提交

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=0;i<n;i++)
	{
		l=1ll*l*k%mod;
		r=1ll*r*inv%mod;
		ans=(ans+1ll*l*r%mod*(C(n-i,(n-1)*2-i)-C(n-i+1,(n-1)*2-i)+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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 178ms
memory: 160112kb

input:

2
3 1
2 2

output:

1
6

result:

ok 2 number(s): "1 6"

Test #2:

score: -100
Wrong Answer
time: 206ms
memory: 160064kb

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
61990
565
0
2406
1
99
88
1
1
61990
15
1
99
45
22
504
2076
565
1
88
6
54
15952
0
1
5880
45
2406
0
88
22
88
1
0
22
5880
1
1
6
1
565
5880
15
565
45
28
15952
15
1
1
2076
0
15952
0
15952
5880
0
1
99
28
28
1
61990
0
15
1
504
28
28
54
1
1
61990
15
2076
0
1
0
15
99
2076
15952
61990
6
88
2076
88
15
0
0
1...

result:

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