QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422839 | #2834. Nonsense | TianTian2008 | WA | 143ms | 199360kb | C++14 | 1004b | 2024-05-27 19:44:30 | 2024-05-27 19:44:30 |
Judging History
answer
#include <iostream>
#include <cstdio>
#define mod 998244353
using namespace std;
typedef long long ll;
ll n,x,y,q,fac[5001],inv[5001],f[5001][5001];
ll ksm(ll x,ll y) {
ll res=1;
while(y) {
if(y&1) res=res*x%mod;
x=x*x%mod;
y>>=1;
}
return res;
}
inline ll binom(ll x) {return fac[x]*inv[x]%mod;}
void init() {
ll m=min(n,5000ll);
fac[0]=1;
for(int i=1;i<=m;++i) fac[i]=fac[i-1]*(n-i+2)%mod;
ll pro=1;
for(int i=1;i<=m;++i) pro=pro*i%mod;
inv[m]=ksm(pro,mod-2);
for(int i=m;i>=1;--i) inv[i-1]=inv[i]*i%mod;
ll div=ksm(x-y,mod-2);
for(int i=0;i<=m;++i)
for(int j=0;j<=m;++j) {
if(i==0) f[i][j]=-binom(j)*ksm(y,n+1-j)%mod;
else f[i][j]=-f[i-1][j];
if(j==0) f[i][j]+=binom(i)*ksm(x,n+1-i)%mod;
else f[i][j]+=f[i][j-1];
f[i][j]=f[i][j]*div%mod;
}
}
int main() {
while(scanf("%lld%lld%lld%lld",&n,&x,&y,&q)!=EOF) {
init();
ll a,b;
while(q--) {
scanf("%lld%lld",&a,&b);
printf("%lld\n",f[a][b]);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8092kb
input:
3 1 2 2 1 1 1 2 100 2 3 1 1 1
output:
6 1 866021789
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 143ms
memory: 199360kb
input:
1000000000 0 1 1 1000 1000 2 0 0 1 1 1 2 998244352 998244352 1 1 1
output:
381781645 0 0
result:
wrong answer 2nd lines differ - expected: '1', found: '0'