QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#333881#8047. DFS Order 4LarunatrecyWA 990ms6440kbC++14834b2024-02-20 18:35:292024-02-20 18:35:30

Judging History

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

  • [2024-02-20 18:35:30]
  • 评测
  • 测评结果:WA
  • 用时:990ms
  • 内存:6440kb
  • [2024-02-20 18:35:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 880;
int n,mod;
int inv[N];
int dp[N][N],f[N];//点数,层数 
inline int myplus(int a,int b){return a+b>=mod?a+b-mod:a+b;}
inline int reduce(int a,int b){return a-b<0?a-b+mod:a-b;}
int main()
{
	cin>>n>>mod;
	inv[1]=1;
	for(int i=2;i<=n;i++)inv[i]=1ll*inv[mod%i]*(mod-mod/i)%mod;
	dp[1][0]=1;
	for(int i=2;i<=n;i++)
	for(int j=0;j<=i;j++)
	{
		dp[i][j]=myplus(dp[i][j],dp[i-1][j+1]);
		if(j==0)dp[i][0]=myplus(dp[i][0],dp[i-1][0]);
		for(int k=1;k<=i-j;k++)
		{
			dp[i][j]=myplus(dp[i][j],1ll*dp[i-k][j]*dp[k-1][0]%mod);
			if(j)dp[i][j]=reduce(dp[i][j],1ll*dp[i-k][j-1]*(dp[k-1][0]+(k==1))%mod);
		}
		dp[i][j]=1ll*dp[i][j]*inv[i]%mod;
	} 
	int ans=1ll*dp[n-1][0]*inv[n]%mod;
	for(int i=1;i<=n;i++)ans=1ll*ans*i%mod;
	cout<<ans;
	return 0;
} 

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3528kb

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 828ms
memory: 6108kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 964ms
memory: 6328kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

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

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 882ms
memory: 6252kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 817ms
memory: 6092kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 904ms
memory: 6228kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 981ms
memory: 6440kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 969ms
memory: 6328kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 893ms
memory: 6268kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 990ms
memory: 6384kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

score: -100
Wrong Answer
time: 0ms
memory: 3596kb

input:

1 1001338769

output:

0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'