QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#501576 | #8047. DFS Order 4 | Williamxzh | WA | 982ms | 8820kb | C++23 | 1.0kb | 2024-08-02 20:58:53 | 2024-08-02 20:58:54 |
Judging History
answer
#include <bits/stdc++.h>
#define il inline
using namespace std;
typedef long long ll;ll mod;
il void add(ll &x,ll y){x=(x+y>=mod?x+y-mod:x+y);}
il void del(ll &x,ll y){x=(x<y?x-y+mod:x-y);}
il ll qp(ll a,ll b){
ll ans=1ll;
while(b){
if(b&1) ans=(ans*a)%mod;
a=(a*a)%mod,b>>=1;
}return ans;
}
const int N=803;
int n;ll f[N][N],fac[N],inv[N];
il void init(){
fac[0]=1ll;for(int i=1;i<=n;++i) fac[i]=(fac[i-1]*1ll*i)%mod;
for(int i=1;i<=n;++i) inv[i]=qp(i,mod-2ll);
}
int main(){
//freopen("qoj8047_0.in","r",stdin);
scanf("%d%lld",&n,&mod);init();
f[1][0]=1ll;
for(int i=2;i<n;++i)
for(int k=0;k<=i;++k){
f[i][k]=f[i-1][k+1]*inv[i]%mod;
if(!k) add(f[i][0],f[i-1][0]*inv[i]%mod);
for(int j=1;j<=i-k;++j){
add(f[i][k],f[j-1][0]*f[i-j][k]%mod*inv[i]%mod);
if(k) del(f[i][k],(f[j-1][0]+(j==1))*f[i-j][k-1]%mod*inv[i]%mod);
}
}
printf("%lld",f[n-1][0]*fac[n-1]%mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3816kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3908kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 3ms
memory: 4132kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 822ms
memory: 8304kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 956ms
memory: 8820kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 838ms
memory: 8616kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 885ms
memory: 8492kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 813ms
memory: 8216kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 895ms
memory: 8512kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 970ms
memory: 8644kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 967ms
memory: 8596kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 889ms
memory: 8448kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 982ms
memory: 8720kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: -100
Wrong Answer
time: 0ms
memory: 3892kb
input:
1 1001338769
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'