QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#339094#8047. DFS Order 4L_fireAC ✓1009ms8216kbC++141.2kb2024-02-26 19:10:142024-02-26 19:10:17

Judging History

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

  • [2024-02-26 19:10:17]
  • 评测
  • 测评结果:AC
  • 用时:1009ms
  • 内存:8216kb
  • [2024-02-26 19:10:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
struct IO{
	int rd()
	{
		int x=0,w=1;
		char c=getchar();
		while(c<'0'||c>'9')
		{
			if(c=='-') w=-1;
			c=getchar();
		}
		while(c>='0'&&c<='9')
		{
			x=(x<<3)+(x<<1)+c-'0';
			c=getchar();
		}
		return x*w;
	}
	void write(int x)
	{
		if(x<0) putchar('-'),x=-x;
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	void wt(int x,char c){write(x);putchar(c);}
}io;
int inv[200100];
int n,mod;
int dp[808][808];
signed main()
{
	// freopen("txt.in","r",stdin);
	// freopen("txt.out","w",stdout);
	// cin>>n;
	cin>>n>>mod;
	if(n==1){puts("1");return 0;}
	inv[1]=1;
	for(int i=2;i<=n;i++) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	dp[1][0]=1;
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<=i;j++)
		{
			dp[i][j]=(dp[i][j]+dp[i-1][j+1])%mod;
			if(j==0) dp[i][0]=(dp[i][0]+dp[i-1][0])%mod;
			for(int k=0;k<=i-j;k++)
			{
				dp[i][j]=(dp[i][j]+(dp[i-k][j]*dp[k-1][0]%mod))%mod;
				if(j) dp[i][j]=(dp[i][j]-1ll*(dp[i-k][j-1]*(dp[k-1][0]+(k==1)))%mod)%mod;
			}
			dp[i][j]=dp[i][j]*inv[i]%mod;
		}
	}
	int ans=dp[n-1][0]*inv[n];
	for(int i=1;i<=n;i++) ans=ans*i%mod;
	cout<<ans<<endl;
	// fclose(stdin);fclose(stdout);
	return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3616kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 842ms
memory: 7976kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 978ms
memory: 8216kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 860ms
memory: 8060kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 891ms
memory: 8172kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 825ms
memory: 8016kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 922ms
memory: 8172kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 989ms
memory: 8188kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 1000ms
memory: 8216kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 902ms
memory: 8168kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 1009ms
memory: 8192kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: 0
Accepted
time: 1ms
memory: 3668kb

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed