QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#804018#9561. 树数叔术Larunatrecy100 ✓242ms3956kbC++141.2kb2024-12-07 19:55:082024-12-07 19:55:10

Judging History

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

  • [2024-12-07 19:55:10]
  • 评测
  • 测评结果:100
  • 用时:242ms
  • 内存:3956kb
  • [2024-12-07 19:55:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
    x=0;char c=getchar();bool f=0;
    for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
    x=(f?-x:x);
}
typedef long long LL;
const int N = 200;
int n,V,mod;
int f[N][N],g[N][N],C[N][N];
inline int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int main()
{
	read(n);read(V);read(mod);
	if(V>=n)
	{
		cout<<0;
		return 0;
	}
	for(int i=2;i<=n;i++)
	f[i][2]=1;
	C[0][0]=1;
	for(int i=1;i<=n;i++)
	{
		C[i][0]=1;
		for(int j=1;j<=i;j++)
		C[i][j]=add(C[i-1][j-1],C[i-1][j]);
	}
	int cur=1;
	for(int i=2;i<=V;i++)
	{
		for(int j=2;j<=n;j++)
		{
			for(int k=2;k<=j;k++)
			{
				for(int l=1;l<=j-k;l++)
				g[j][k+l]=add(g[j][k+l],1ll*f[j][k]*C[j-k][l]%mod);	
			}
		}
		for(int k=2;k<=n;k++)
		{
			int v=0;
			for(int j=2;j<=n;j++)
			{
				g[j][k]=add(g[j][k],v);
				v=add(v,1ll*f[j][k-1]*j%mod);
			}
		}
		for(int j=2;j<=n;j++)
		for(int k=2;k<=j;k++)
		f[j][k]=g[j][k],g[j][k]=0;
	}
	int ans=f[n][n];
	for(int i=1;i<=n;i++)ans=1ll*ans*i%mod;
	cout<<ans;
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 3524kb

input:

1 1 624295285

output:

0

result:

ok single line: '0'

Test #2:

score: 5
Accepted
time: 0ms
memory: 3544kb

input:

4 684813415 564954712

output:

0

result:

ok single line: '0'

Test #3:

score: 5
Accepted
time: 0ms
memory: 3680kb

input:

4 2 844826878

output:

24

result:

ok single line: '24'

Test #4:

score: 5
Accepted
time: 0ms
memory: 3484kb

input:

4 17724073 252218682

output:

0

result:

ok single line: '0'

Test #5:

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

input:

4 3 697681963

output:

384

result:

ok single line: '384'

Subtask #2:

score: 15
Accepted

Test #6:

score: 15
Accepted
time: 0ms
memory: 3620kb

input:

6 4 956647977

output:

238320

result:

ok single line: '238320'

Test #7:

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

input:

6 450615260 491361886

output:

0

result:

ok single line: '0'

Test #8:

score: 15
Accepted
time: 0ms
memory: 3632kb

input:

6 5 339344353

output:

933120

result:

ok single line: '933120'

Test #9:

score: 15
Accepted
time: 0ms
memory: 3636kb

input:

6 3 842228619

output:

23760

result:

ok single line: '23760'

Test #10:

score: 15
Accepted
time: 0ms
memory: 3636kb

input:

6 5 331699652

output:

933120

result:

ok single line: '933120'

Subtask #3:

score: 30
Accepted

Test #11:

score: 30
Accepted
time: 2ms
memory: 3640kb

input:

48 26 424594716

output:

362283012

result:

ok single line: '362283012'

Test #12:

score: 30
Accepted
time: 0ms
memory: 3528kb

input:

49 1000000000 738885247

output:

0

result:

ok single line: '0'

Test #13:

score: 30
Accepted
time: 3ms
memory: 3724kb

input:

48 39 688951620

output:

598399200

result:

ok single line: '598399200'

Test #14:

score: 30
Accepted
time: 0ms
memory: 3536kb

input:

50 476039414 292870080

output:

0

result:

ok single line: '0'

Test #15:

score: 30
Accepted
time: 3ms
memory: 3732kb

input:

50 48 245196368

output:

123576912

result:

ok single line: '123576912'

Subtask #4:

score: 50
Accepted

Test #16:

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

input:

150 526250070 197316869

output:

0

result:

ok single line: '0'

Test #17:

score: 50
Accepted
time: 188ms
memory: 3884kb

input:

149 116 671784452

output:

18945228

result:

ok single line: '18945228'

Test #18:

score: 50
Accepted
time: 215ms
memory: 3832kb

input:

146 144 906402626

output:

438777234

result:

ok single line: '438777234'

Test #19:

score: 50
Accepted
time: 222ms
memory: 3940kb

input:

147 143 705666477

output:

70408701

result:

ok single line: '70408701'

Test #20:

score: 50
Accepted
time: 242ms
memory: 3956kb

input:

150 147 453481175

output:

336290325

result:

ok single line: '336290325'