QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#387599#8047. DFS Order 4union_of_britainAC ✓1455ms15168kbC++14890b2024-04-12 17:17:012024-04-12 17:17:01

Judging History

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

  • [2024-04-12 17:17:01]
  • 评测
  • 测评结果:AC
  • 用时:1455ms
  • 内存:15168kb
  • [2024-04-12 17:17:01]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int maxn=1605;
int n,mod;
int fac[maxn],ifac[maxn],inv[maxn],f[maxn][maxn];
int qp(int a,int b){
	if(b==0)return 1;
	int t=qp(a,b>>1);
	t=(t*t)%mod;
	if(b&1)t=(t*a)%mod;
	return t;
}
signed main(){
   ios::sync_with_stdio(false);
   cin.tie(0);cout.tie(0);
   cin>>n>>mod;
   fac[0]=1;
   for(int i=1;i<=n;i++)fac[i]=(fac[i-1]*i)%mod;
   ifac[n]=qp(fac[n],mod-2);
   for(int i=n-1;i>=0;i--)ifac[i]=(ifac[i+1]*(i+1))%mod;
   for(int i=1;i<=n;i++)inv[i]=ifac[i]*fac[i-1]%mod;
   f[1][0]=1;inv[0]=1;
   for(int i=2;i<=n;i++){
		for(int j=0;j<=n;j++){
			int res=f[i-1][0];
			for(int k=2;k<i-1;k++)(res+=(f[k][0]-f[k][i+j-k-1]+mod)%mod*f[i-k][j])%=mod;
			f[i][j]=res*inv[i+j-1]%mod;
			// cerr<<i<<" "<<j<<" "<<f[i][j]<<endl;
		}
   }
   cout<<f[n][0]*fac[n-1]%mod<<endl;
   return 0;
}

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

詳細信息

Test #1:

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

input:

4 114514199

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 998244353

output:

11033

result:

ok 1 number(s): "11033"

Test #3:

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

input:

100 1000000007

output:

270904395

result:

ok 1 number(s): "270904395"

Test #4:

score: 0
Accepted
time: 1233ms
memory: 12968kb

input:

756 1001338769

output:

901942543

result:

ok 1 number(s): "901942543"

Test #5:

score: 0
Accepted
time: 1433ms
memory: 14992kb

input:

793 1009036033

output:

301770320

result:

ok 1 number(s): "301770320"

Test #6:

score: 0
Accepted
time: 1257ms
memory: 13372kb

input:

759 1005587659

output:

846376219

result:

ok 1 number(s): "846376219"

Test #7:

score: 0
Accepted
time: 1326ms
memory: 14848kb

input:

773 1007855479

output:

1398019

result:

ok 1 number(s): "1398019"

Test #8:

score: 0
Accepted
time: 1219ms
memory: 14376kb

input:

751 1006730639

output:

321287237

result:

ok 1 number(s): "321287237"

Test #9:

score: 0
Accepted
time: 1356ms
memory: 13280kb

input:

778 1007760653

output:

430322899

result:

ok 1 number(s): "430322899"

Test #10:

score: 0
Accepted
time: 1454ms
memory: 14340kb

input:

798 1007543827

output:

688720826

result:

ok 1 number(s): "688720826"

Test #11:

score: 0
Accepted
time: 1447ms
memory: 15048kb

input:

796 1004841413

output:

258829347

result:

ok 1 number(s): "258829347"

Test #12:

score: 0
Accepted
time: 1339ms
memory: 14064kb

input:

775 1005185189

output:

744278608

result:

ok 1 number(s): "744278608"

Test #13:

score: 0
Accepted
time: 1455ms
memory: 15168kb

input:

800 1006012831

output:

508549367

result:

ok 1 number(s): "508549367"

Test #14:

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

input:

1 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #15:

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

input:

2 1001338769

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

9 1009036033

output:

1780

result:

ok 1 number(s): "1780"

Test #17:

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

input:

14 1001338769

output:

43297358

result:

ok 1 number(s): "43297358"

Extra Test:

score: 0
Extra Test Passed