QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#415112#6678. Gem Island 2FlamireAC ✓819ms384592kbC++171.3kb2024-05-20 11:12:002024-05-20 11:12:00

Judging History

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

  • [2024-05-20 11:12:00]
  • 评测
  • 测评结果:AC
  • 用时:819ms
  • 内存:384592kb
  • [2024-05-20 11:12:00]
  • 提交

answer

#include <bits/stdc++.h>
#define N 30000011
using namespace std;
int n,d,r,fac[N],ifac[N],R[N],F[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)
{
	if(m<0)return 0;
	if(!n)return 1;
	return m&1?-binom(n-1,m):binom(n-1,m);
}
bool is[N];int pr[N/10];
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]=(j&1?-1:1)*(1ll*j*-Sn(j-1,r-1)+1ll*r*-Sn(j,r))%p*binom(n,j)%p;
	}
	for(int j=1;j<=d;++j)F[j]=binom(n+d-1-j,n-1);
	is[0]=is[1]=1;
	for(int i=2;i<=d;++i)
	{
		if(!is[i])pr[++pr[0]]=i;
		for(int j=1;j<=pr[0]&&i*pr[j]<=d;++j)
		{
			is[i*pr[j]]=1;
			if(i%pr[j]==0)break;
		}
	}
	for(int i=1;i<=pr[0];++i)
	{
		for(int j=d/pr[i];j;--j)
		{
			F[j]=(F[j]+F[j*pr[i]])%p;
		}
	}
	for(int j=1;j<=d;++j)ans=(ans+1ll*F[j]*R[j])%p;
	int denom=binom(n+d-1,n-1);
	printf("%d\n",(1ll*ans*qpow(denom,p-2)%p+r+p)%p);
	fclose(stdin);fclose(stdout);return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 259ms
memory: 244352kb

input:

2 3 1

output:

499122180

result:

ok 1 number(s): "499122180"

Test #2:

score: 0
Accepted
time: 256ms
memory: 245504kb

input:

3 3 2

output:

698771052

result:

ok 1 number(s): "698771052"

Test #3:

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

input:

5 10 3

output:

176512750

result:

ok 1 number(s): "176512750"

Test #4:

score: 0
Accepted
time: 263ms
memory: 245968kb

input:

5 4 3

output:

71303175

result:

ok 1 number(s): "71303175"

Test #5:

score: 0
Accepted
time: 263ms
memory: 246028kb

input:

37 47 12

output:

962577218

result:

ok 1 number(s): "962577218"

Test #6:

score: 0
Accepted
time: 252ms
memory: 245676kb

input:

29 50 26

output:

175627840

result:

ok 1 number(s): "175627840"

Test #7:

score: 0
Accepted
time: 247ms
memory: 245700kb

input:

298 498 221

output:

765832019

result:

ok 1 number(s): "765832019"

Test #8:

score: 0
Accepted
time: 251ms
memory: 245412kb

input:

497 456 243

output:

414028615

result:

ok 1 number(s): "414028615"

Test #9:

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

input:

114514 1926 817

output:

691374994

result:

ok 1 number(s): "691374994"

Test #10:

score: 0
Accepted
time: 259ms
memory: 246244kb

input:

1919810 1554 1999

output:

3553

result:

ok 1 number(s): "3553"

Test #11:

score: 0
Accepted
time: 241ms
memory: 244736kb

input:

1926817 1514 1001

output:

685086550

result:

ok 1 number(s): "685086550"

Test #12:

score: 0
Accepted
time: 259ms
memory: 245476kb

input:

1432132 1425 1425

output:

2850

result:

ok 1 number(s): "2850"

Test #13:

score: 0
Accepted
time: 717ms
memory: 384580kb

input:

14999999 15000000 14999999

output:

29999999

result:

ok 1 number(s): "29999999"

Test #14:

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

input:

98765 99654 85647

output:

815183913

result:

ok 1 number(s): "815183913"

Test #15:

score: 0
Accepted
time: 260ms
memory: 245840kb

input:

99999 100000 99998

output:

832290200

result:

ok 1 number(s): "832290200"

Test #16:

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

input:

1541 99998 725

output:

463021366

result:

ok 1 number(s): "463021366"

Test #17:

score: 0
Accepted
time: 287ms
memory: 256168kb

input:

985438 998756 101254

output:

671487608

result:

ok 1 number(s): "671487608"

Test #18:

score: 0
Accepted
time: 288ms
memory: 257524kb

input:

998654 999856 2

output:

92085960

result:

ok 1 number(s): "92085960"

Test #19:

score: 0
Accepted
time: 270ms
memory: 253988kb

input:

45876 1000000 13

output:

208089291

result:

ok 1 number(s): "208089291"

Test #20:

score: 0
Accepted
time: 785ms
memory: 384592kb

input:

15000000 14999999 514

output:

143843956

result:

ok 1 number(s): "143843956"

Test #21:

score: 0
Accepted
time: 797ms
memory: 384520kb

input:

14985345 14999998 145124

output:

785676527

result:

ok 1 number(s): "785676527"

Test #22:

score: 0
Accepted
time: 819ms
memory: 384592kb

input:

14855345 14993298 1451424

output:

779861797

result:

ok 1 number(s): "779861797"

Test #23:

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

input:

1 1 1

output:

2

result:

ok 1 number(s): "2"

Test #24:

score: 0
Accepted
time: 714ms
memory: 384528kb

input:

15000000 15000000 15000000

output:

30000000

result:

ok 1 number(s): "30000000"

Extra Test:

score: 0
Extra Test Passed