QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388951#8047. DFS Order 4zhouhuanyiAC ✓1790ms21372kbC++142.6kb2024-04-13 21:57:042024-04-13 21:57:05

Judging History

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

  • [2024-04-13 21:57:05]
  • 评测
  • 测评结果:AC
  • 用时:1790ms
  • 内存:21372kb
  • [2024-04-13 21:57:04]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 802
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
int n,F[N+1],pw[N+1][N+1],dp[N+1][N+1],DP[N+1][N+1],sdp[N+1][N+1],sDP[N+1][N+1],delta[N+1],sdelta[N+1][N+1],mod,fac[N+1],invfac[N+1],inv[N+1],C[N+1][N+1];
unsigned long long d;
int fast_pow(int a,int b)
{
	int res=1,mul=a;
	while (b)
	{
		if (b&1) res=1ll*res*mul%mod;
		mul=1ll*mul*mul%mod,b>>=1;
	}
	return res;
}
void Adder(int &x,int d)
{
	x+=d;
	if (x>=mod) x-=mod;
	return;
}
void Adder2(int &x,int d)
{
	x+=d;
	if (x<0) x+=mod;
	return;
}
int MD(int x)
{
	return x>=mod?x-mod:x;
}
int MD2(int x)
{
	return x<0?x+mod:x;
}
int get_mod(long long x)
{
	int r=x-(((__int128)(x)*d)>>64)*mod;
	return r>=mod?r-mod:r;
}
void laguange(int x)
{
	for (int i=1;i<=n+1;++i)
		for (int j=0;j<=F[x];++j)
			Adder(DP[x][j],get_mod(1ll*sDP[x][i]*sdelta[i][j]));
	return;
}
void get(int x)
{
	for (int i=1;i<=n+1;++i)
		for (int j=0;j<=F[x];++j)
			Adder(sdp[x][i],get_mod(1ll*dp[x][j]*pw[i][j]));
	return;
}
int main()
{
	n=read(),mod=read(),d=-1ull/mod,fac[0]=1;
	if (n==1)
	{
		puts("1");
		return 0;
	}
	for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
	invfac[N]=fast_pow(fac[N],mod-2);
	for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
	for (int i=1;i<=N;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
	for (int i=0;i<=N;++i)
		for (int j=0;j<=i;++j)
			C[i][j]=1ll*fac[i]*invfac[j]%mod*invfac[i-j]%mod;
	for (int i=1;i<=n+1;++i)
	{
		pw[i][0]=1;
		for (int j=1;j<=n;++j) pw[i][j]=1ll*pw[i][j-1]*i%mod;
	}
	for (int i=1;i<=n+1;++i) sDP[0][i]=1;
	delta[0]=1;
	for (int i=1;i<=n+1;++i)
	{
		for (int j=n;j>=1;--j) delta[j]=MD2(delta[j-1]-1ll*i*delta[j]%mod);
		delta[0]=MD2(-1ll*i*delta[0]%mod);
	}
	for (int i=1;i<=n+1;++i)
	{
		delta[0]=MD2(-1ll*inv[i]*delta[0]%mod);
		for (int j=1;j<=n;++j) delta[j]=1ll*inv[i]*MD2(delta[j-1]-delta[j])%mod;
		for (int j=0;j<=n;++j)
		{
			if (!((n+1-i)&1)) sdelta[i][j]=1ll*delta[j]*invfac[i-1]%mod*invfac[n+1-i]%mod;
			else sdelta[i][j]=MD2(-1ll*delta[j]*invfac[i-1]%mod*invfac[n+1-i]%mod);
		}
		for (int j=n;j>=1;--j) delta[j]=MD2(delta[j-1]-1ll*i*delta[j]%mod);
		delta[0]=MD2(-1ll*i*delta[0]%mod);
	}
	for (int i=0;i<=n;++i) F[i]=min(i,n-i+1);
	for (int i=1;i<=n;++i)
	{
		laguange(i-1);
		for (int j=0;j<=F[i];++j) Adder(dp[i][max(j-1,1)],DP[i-1][j]);
		get(i);
		for (int j=1;j<=i;++j)
			for (int k=1;k<=n+1;++k)
				Adder(sDP[i][k],get_mod(1ll*get_mod(1ll*sDP[i-j][k]*sdp[j][k])*C[i-1][j-1]));
	}
	printf("%d\n",DP[n-1][1]);
	return 0;
}

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

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 6416kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 6516kb

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

score: 0
Accepted
time: 8ms
memory: 8260kb

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 1517ms
memory: 20668kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 1752ms
memory: 21264kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 1519ms
memory: 20672kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 1609ms
memory: 20960kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 1473ms
memory: 20644kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 1637ms
memory: 21028kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 1784ms
memory: 21352kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 1766ms
memory: 21372kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 1614ms
memory: 20912kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 1790ms
memory: 21356kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: 0
Accepted
time: 0ms
memory: 3720kb

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

score: 0
Accepted
time: 0ms
memory: 6412kb

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

score: 0
Accepted
time: 3ms
memory: 6668kb

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

score: 0
Accepted
time: 0ms
memory: 6668kb

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed