QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388948 | #8047. DFS Order 4 | zhouhuanyi | WA | 1738ms | 21460kb | C++14 | 2.6kb | 2024-04-13 21:56:00 | 2024-04-13 21:56:01 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 802
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int n,F[N+1],pw[N+1][N+1],dp[N+1][N+1],DP[N+1][N+1],sdp[N+1][N+1],sDP[N+1][N+1],delta[N+1],sdelta[N+1][N+1],mod,fac[N+1],invfac[N+1],inv[N+1],C[N+1][N+1];
unsigned long long d;
int fast_pow(int a,int b)
{
int res=1,mul=a;
while (b)
{
if (b&1) res=1ll*res*mul%mod;
mul=1ll*mul*mul%mod,b>>=1;
}
return res;
}
void Adder(int &x,int d)
{
x+=d;
if (x>=mod) x-=mod;
return;
}
void Adder2(int &x,int d)
{
x+=d;
if (x<0) x+=mod;
return;
}
int MD(int x)
{
return x>=mod?x-mod:x;
}
int MD2(int x)
{
return x<0?x+mod:x;
}
int get_mod(long long x)
{
int r=x-(((__int128)(x)*d)>>64)*mod;
return r>=mod?r-mod:r;
}
void laguange(int x)
{
for (int i=1;i<=n+1;++i)
for (int j=0;j<=F[x];++j)
Adder(DP[x][j],get_mod(1ll*sDP[x][i]*sdelta[i][j]));
return;
}
void get(int x)
{
for (int i=1;i<=n+1;++i)
for (int j=0;j<=F[x];++j)
Adder(sdp[x][i],get_mod(1ll*dp[x][j]*pw[i][j]));
return;
}
int main()
{
n=read(),mod=read(),d=-1ull/mod,fac[0]=1;
for (int i=1;i<=N;++i) fac[i]=1ll*fac[i-1]*i%mod;
invfac[N]=fast_pow(fac[N],mod-2);
for (int i=N-1;i>=0;--i) invfac[i]=1ll*invfac[i+1]*(i+1)%mod;
for (int i=1;i<=N;++i) inv[i]=1ll*fac[i-1]*invfac[i]%mod;
for (int i=0;i<=N;++i)
for (int j=0;j<=i;++j)
C[i][j]=1ll*fac[i]*invfac[j]%mod*invfac[i-j]%mod;
for (int i=1;i<=n+1;++i)
{
pw[i][0]=1;
for (int j=1;j<=n;++j) pw[i][j]=1ll*pw[i][j-1]*i%mod;
}
for (int i=1;i<=n+1;++i) sDP[0][i]=1;
delta[0]=1;
for (int i=1;i<=n+1;++i)
{
for (int j=n;j>=1;--j) delta[j]=MD2(delta[j-1]-1ll*i*delta[j]%mod);
delta[0]=MD2(-1ll*i*delta[0]%mod);
}
for (int i=1;i<=n+1;++i)
{
delta[0]=MD2(-1ll*inv[i]*delta[0]%mod);
for (int j=1;j<=n;++j) delta[j]=1ll*inv[i]*MD2(delta[j-1]-delta[j])%mod;
for (int j=0;j<=n;++j)
{
if (!((n+1-i)&1)) sdelta[i][j]=1ll*delta[j]*invfac[i-1]%mod*invfac[n+1-i]%mod;
else sdelta[i][j]=MD2(-1ll*delta[j]*invfac[i-1]%mod*invfac[n+1-i]%mod);
}
for (int j=n;j>=1;--j) delta[j]=MD2(delta[j-1]-1ll*i*delta[j]%mod);
delta[0]=MD2(-1ll*i*delta[0]%mod);
}
for (int i=0;i<=n;++i) F[i]=min(i,n-i+1);
for (int i=1;i<=n;++i)
{
laguange(i-1);
for (int j=0;j<=F[i];++j) Adder(dp[i][max(j-1,1)],DP[i-1][j]);
get(i);
for (int j=1;j<=i;++j)
for (int k=1;k<=n+1;++k)
Adder(sDP[i][k],get_mod(1ll*get_mod(1ll*sDP[i-j][k]*sdp[j][k])*C[i-1][j-1]));
}
printf("%d\n",DP[n-1][1]);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 11640kb
input:
4 114514199
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 4ms
memory: 12004kb
input:
10 998244353
output:
11033
result:
ok 1 number(s): "11033"
Test #3:
score: 0
Accepted
time: 4ms
memory: 13868kb
input:
100 1000000007
output:
270904395
result:
ok 1 number(s): "270904395"
Test #4:
score: 0
Accepted
time: 1472ms
memory: 20852kb
input:
756 1001338769
output:
901942543
result:
ok 1 number(s): "901942543"
Test #5:
score: 0
Accepted
time: 1683ms
memory: 21372kb
input:
793 1009036033
output:
301770320
result:
ok 1 number(s): "301770320"
Test #6:
score: 0
Accepted
time: 1496ms
memory: 21180kb
input:
759 1005587659
output:
846376219
result:
ok 1 number(s): "846376219"
Test #7:
score: 0
Accepted
time: 1572ms
memory: 21124kb
input:
773 1007855479
output:
1398019
result:
ok 1 number(s): "1398019"
Test #8:
score: 0
Accepted
time: 1432ms
memory: 20720kb
input:
751 1006730639
output:
321287237
result:
ok 1 number(s): "321287237"
Test #9:
score: 0
Accepted
time: 1598ms
memory: 21144kb
input:
778 1007760653
output:
430322899
result:
ok 1 number(s): "430322899"
Test #10:
score: 0
Accepted
time: 1730ms
memory: 21460kb
input:
798 1007543827
output:
688720826
result:
ok 1 number(s): "688720826"
Test #11:
score: 0
Accepted
time: 1723ms
memory: 21440kb
input:
796 1004841413
output:
258829347
result:
ok 1 number(s): "258829347"
Test #12:
score: 0
Accepted
time: 1587ms
memory: 21108kb
input:
775 1005185189
output:
744278608
result:
ok 1 number(s): "744278608"
Test #13:
score: 0
Accepted
time: 1738ms
memory: 21412kb
input:
800 1006012831
output:
508549367
result:
ok 1 number(s): "508549367"
Test #14:
score: -100
Wrong Answer
time: 0ms
memory: 11648kb
input:
1 1001338769
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'