QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#351673 | #8047. DFS Order 4 | Graphcity | WA | 1154ms | 6136kb | C++20 | 1.1kb | 2024-03-12 10:57:21 | 2024-03-12 10:57:22 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rof(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int Maxn=800;
int f[Maxn+5][Maxn+5],iv[Maxn+5],n,Mod;
inline int Pow(int x,int y)
{
int res=1;
while(y)
{
if(y&1) res=1ll*res*x%Mod;
x=1ll*x*x%Mod,y>>=1;
}
return res;
}
// inline int Fac(int x) {int res=1; For(i,1,x) res=1ll*res*i%Mod; return res;}
int main()
{
// freopen("1.in","r",stdin);
cin>>n>>Mod; f[1][0]=1;
For(i,1,n) iv[i]=Pow(i,Mod-2);
For(i,2,n) For(j,0,i-1)
{
f[i][j]=(j==0?1ll:Mod-1ll)*(f[i-j-1][0]+(j+1==i))%Mod*iv[i]%Mod;
// if(i==3 && j==0) cerr<<f[i][j]*6%Mod<<endl;
For(k,1,i-j-2) f[i][j]=(f[i][j]+1ll*f[i-k-1][j]*f[k][0]%Mod*iv[i])%Mod;
// if(i==3 && j==0) cerr<<f[i][j]*6%Mod<<endl;
For(k,1,i-j-2) f[i][j]=(f[i][j]+1ll*f[k+j][j]*f[i-1][j+k]%Mod*iv[i])%Mod;
// cerr<<i<<' '<<j<<' '<<1ll*f[i][j]*Fac(i)%Mod<<endl;
}
int ans=f[n-1][0];
For(i,1,n-1) ans=1ll*ans*i%Mod;
cout<<ans<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 3ms
memory: 3912kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 987ms
memory: 5980kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 1132ms
memory: 6100kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 991ms
memory: 6072kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 1046ms
memory: 6036kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 959ms
memory: 6108kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 1064ms
memory: 5976kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 1150ms
memory: 6120kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 1142ms
memory: 6020kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 1054ms
memory: 5980kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 1154ms
memory: 6136kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: -100
Wrong Answer
time: 0ms
memory: 3532kb
input:
1 1001338769
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'