QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#384384 | #8568. Expected Diameter | zhouhuanyi | WA | 6090ms | 50672kb | C++14 | 2.2kb | 2024-04-09 22:35:03 | 2024-04-09 22:35:03 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 2000
#define mod 998244353
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 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 n,x,y,p,ans,fac[N+1],invfac[N+1],inv[N+1],dp[N+1][N+1],delta[N+1],W[N+1],DP[N+1][N+1],F[N+1][N+1];
int main()
{
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;
n=read(),x=read(),y=read(),p=1ll*x*fast_pow(y,mod-2)%mod,dp[0][1]=DP[0][1]=1;
for (int i=1;i<=n;++i)
{
for (int j=1;j<=n;++j)
{
Adder(F[i][j],1ll*p*dp[i-1][j]%mod);
if (i>=2) Adder(F[i][j],1ll*MD2(1-p)*dp[i-2][j]%mod);
}
for (int j=1;j<=n;++j) delta[j]=1ll*F[i][j]*j%mod;
for (int j=0;j<=n;++j) W[j]=0;
W[0]=1;
for (int j=1;j<=n;++j)
{
for (int k=1;k<=j;++k) Adder(W[j],1ll*W[j-k]*delta[k]%mod);
W[j]=1ll*W[j]*inv[j]%mod;
}
for (int j=1;j<=n;++j) dp[i][j]=W[j-1];
}
for (int i=1;i<=n;++i)
for (int j=1;j<=n;++j)
DP[i][j]=MD2(dp[i][j]-dp[i-1][j]);
for (int i=n;i>=1;--i)
for (int j=1;j<=n;++j)
Adder2(F[i][j],-F[i-1][j]);
for (int op=0;op<=1;++op)
for (int i=0;i<=(n<<1);++i)
for (int j=max(i-op,0);j<=min(i+op,n<<1);++j)
for (int k=1;k<=n-1;++k)
{
if (!op) Adder(ans,1ll*p*DP[i][k]%mod*DP[j][n-k]%mod*inv[2]%mod*(i+j+op+1)%mod);
else Adder(ans,1ll*MD2(1-p)*DP[i][k]%mod*DP[j][n-k]%mod*inv[2]%mod*(i+j+op+1)%mod);
}
for (int i=1;i<=n;++i)
{
Adder(ans,1ll*dp[i][n]*(i<<1)%mod);
Adder2(ans,-1ll*dp[i-1][n]*(i<<1)%mod);
for (int j=1;j<=n-1;++j) Adder2(ans,-1ll*dp[i-1][j]*F[i][n-j]%mod*(i<<1)%mod);
}
printf("%lld\n",1ll*ans*fac[n]%mod*fast_pow(n,mod-1-(n-2))%mod);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7964kb
input:
2 1 3
output:
665496237
result:
ok 1 number(s): "665496237"
Test #2:
score: 0
Accepted
time: 1ms
memory: 7916kb
input:
3 2 3
output:
665496238
result:
ok 1 number(s): "665496238"
Test #3:
score: -100
Wrong Answer
time: 6090ms
memory: 50672kb
input:
2000 1 2
output:
720256555
result:
wrong answer 1st numbers differ - expected: '254870088', found: '720256555'