QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#422883 | #2834. Nonsense | TianTian2008 | WA | 0ms | 8048kb | C++14 | 1.4kb | 2024-05-27 20:00:37 | 2024-05-27 20:00:38 |
Judging History
answer
#include <iostream>
#include <cstdio>
#define mod 998244353
using namespace std;
typedef long long ll;
ll n,x,y,q;
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;
}
namespace sol1 {
ll fac[5001],inv[5001],f[5001][5001];
inline ll binom(ll x) {return fac[x]*inv[x]%mod;}
void work() {
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;
}
ll a,b;
while(q--) {
scanf("%lld%lld",&a,&b);
printf("%lld\n",(f[a][b]+mod)%mod);
}
}
}
namespace sol2 {
ll binom(ll n,ll m) {
ll x=1,y=1;
for(int i=1;i<=m;++i) {
x=x*(n-i+1)%mod;
y=y*i%mod;
}
return x*ksm(y,mod-2)%mod;
}
void work() {
ll a,b;
while(q--) {
scanf("%lld%lld",&a,&b);
if(x==0) printf("%lld\n",binom(n-a,b)*ksm(y,n-a-b)%mod);
else printf("%lld\n",binom(n-b,a)*ksm(x,n-a-b)%mod);
}
}
}
int main() {
while(scanf("%lld%lld%lld%lld",&n,&x,&y,&q)!=EOF) {
if(x!=0&&y!=0) sol1::work();
else sol2::work();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 8048kb
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: 0ms
memory: 3900kb
input:
1000000000 0 1 1 1000 1000 2 0 0 1 1 1 2 998244352 998244352 1 1 1
output:
381781645 1 0
result:
wrong answer 3rd lines differ - expected: '1', found: '0'