QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#415111#6678. Gem Island 2FlamireTL 266ms239968kbC++171.8kb2024-05-20 11:05:032024-05-20 11:05:04

Judging History

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

  • [2024-05-20 11:05:04]
  • 评测
  • 测评结果:TL
  • 用时:266ms
  • 内存:239968kb
  • [2024-05-20 11:05:03]
  • 提交

answer

#include <bits/stdc++.h>
#define N 30000011
using namespace std;
int n,d,r,fac[N],ifac[N],R[N];const int p=998244353;
inline int qpow(int bs,int ex){int ans=1;while(ex){if(ex&1)ans=1ll*ans*bs%p;ex>>=1;bs=1ll*bs*bs%p;}return ans;}
inline int binom(int n,int m){if(n<m||m<0)return 0;return 1ll*fac[n]*ifac[m]%p*ifac[n-m]%p;}
int Sn(int n,int m)
{//printf("Sn(%d,%d)\n",n,m);
	if(m<0)return 0;
	if(!n)return 1;
	// int ans=0;
	// for(int i=0;i<=m;++i)ans=(ans+binom(n,i)*(i&1?-1:1))%p;
	// printf("ans:%d ret:%d\n",ans,m&1?-binom(n-1,m):binom(n-1,m));
	return m&1?-binom(n-1,m):binom(n-1,m);
}
int main()
{
	scanf("%d%d%d",&n,&d,&r);
	if(!d){printf("%d\n",r);return 0;}
	fac[0]=1;for(int i=1;i<N;++i)fac[i]=1ll*fac[i-1]*i%p;
	ifac[N-1]=qpow(fac[N-1],p-2);for(int i=N-2;~i;--i)ifac[i]=1ll*ifac[i+1]*(i+1)%p;
	int ans=0;
	for(int j=1;j<=d;++j)
	{
		R[j]=(1ll*j*-Sn(j-1,r-1)+1ll*r*-Sn(j,r))%p*binom(n,j)%p;
	}
	for(int x=2;x<=d+1;++x)
	{
		// printf("====================x:%d\n",x);
		// for(int j=1;n+d-(x-1)*j-1>=n-1;++j)
		// {
		// 	ans=(ans+(j&1?-1ll:1ll)*binom(n,j)*binom(n+d-(x-1)*j-1,n-1)%p*(Sn[j]-1))%p;
		// }
		// for(int k=1;k<=r;++k)
		// {
		// 	for(int i=k;i<=n;++i)
		// 	{
		// 		for(int j=i;n+d-(x-1)*j-1>=n-1&&j<=n;++j)
		// 		{
		// 			ans=(ans+(j-i&1?-1ll:1ll)*binom(j,i)*binom(n,j)%p*binom(n+d-(x-1)*j-1,n-1))%p;
		// 		}
		// 		printf("x:%d k:%d i:%d ans:%d\n",x,k,i,ans);
		// 	}
		// 		printf("x:%d k:%d ans:%d\n",x,k,ans);
		// }
		for(int j=1;n+d-(x-1)*j-1>=n-1;++j)
		{
			int coe=(j&1?-1:1)*binom(n+d-(x-1)*j-1,n-1);
			ans=(ans+1ll*coe*R[j])%p;
		}
		// printf("ans:%d\n",ans);
	}
	// printf("ans:%d\n",ans);
	int denom=binom(n+d-1,n-1);
	// printf("denom:%d\n",denom);
	printf("%d\n",(1ll*ans*qpow(denom,p-2)%p+r+p)%p);
	fclose(stdin);fclose(stdout);return 0;
}

详细

Test #1:

score: 100
Accepted
time: 258ms
memory: 239324kb

input:

2 3 1

output:

499122180

result:

ok 1 number(s): "499122180"

Test #2:

score: 0
Accepted
time: 253ms
memory: 238676kb

input:

3 3 2

output:

698771052

result:

ok 1 number(s): "698771052"

Test #3:

score: 0
Accepted
time: 255ms
memory: 238996kb

input:

5 10 3

output:

176512750

result:

ok 1 number(s): "176512750"

Test #4:

score: 0
Accepted
time: 254ms
memory: 239968kb

input:

5 4 3

output:

71303175

result:

ok 1 number(s): "71303175"

Test #5:

score: 0
Accepted
time: 254ms
memory: 238336kb

input:

37 47 12

output:

962577218

result:

ok 1 number(s): "962577218"

Test #6:

score: 0
Accepted
time: 257ms
memory: 238604kb

input:

29 50 26

output:

175627840

result:

ok 1 number(s): "175627840"

Test #7:

score: 0
Accepted
time: 258ms
memory: 238464kb

input:

298 498 221

output:

765832019

result:

ok 1 number(s): "765832019"

Test #8:

score: 0
Accepted
time: 258ms
memory: 239296kb

input:

497 456 243

output:

414028615

result:

ok 1 number(s): "414028615"

Test #9:

score: 0
Accepted
time: 266ms
memory: 239832kb

input:

114514 1926 817

output:

691374994

result:

ok 1 number(s): "691374994"

Test #10:

score: 0
Accepted
time: 261ms
memory: 239768kb

input:

1919810 1554 1999

output:

3553

result:

ok 1 number(s): "3553"

Test #11:

score: 0
Accepted
time: 249ms
memory: 238568kb

input:

1926817 1514 1001

output:

685086550

result:

ok 1 number(s): "685086550"

Test #12:

score: 0
Accepted
time: 242ms
memory: 238564kb

input:

1432132 1425 1425

output:

2850

result:

ok 1 number(s): "2850"

Test #13:

score: -100
Time Limit Exceeded

input:

14999999 15000000 14999999

output:


result: