QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#423265 | #2834. Nonsense | TianTian2008 | WA | 16ms | 84936kb | C++14 | 1.5kb | 2024-05-27 21:58:52 | 2024-05-27 21:58:54 |
Judging History
answer
#include <iostream>
#include <cstdio>
#define mod 998244353
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pr;
ll n,m,x,y,q,fac[10010],inv[10010],px[10010],py[10010];
pr a[200001];
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;
}
void init() {
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;
px[m]=ksm(x,n+1-m);
for(int i=m;i>=1;--i) px[i-1]=px[i]*x%mod;
py[m]=ksm(y,n+1-m);
for(int i=m;i>=1;--i) py[i-1]=py[i]*y%mod;
}
inline ll binom(ll x) {return fac[x]*inv[x]%mod;}
namespace sol1 {
ll f[5010][5010];
void work() {
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)*py[j]%mod;
else f[i][j]=-f[i-1][j];
if(j==0) f[i][j]+=binom(i)*px[i]%mod;
else f[i][j]+=f[i][j-1];
f[i][j]=f[i][j]*div%mod;
}
for(int i=1;i<=q;++i) printf("%lld\n",(f[a[i].first][a[i].second]+mod)%mod);
}
}
namespace sol2 {
void work() {
for(int i=1;i<=q;++i) printf("%lld\n",px[a[i].first+a[i].second+1]*binom(a[i].first+a[i].second+1));
}
}
int main() {
while(scanf("%lld%lld%lld%lld",&n,&x,&y,&q)!=EOF) {
m=0;
for(int i=1;i<=q;++i) {
scanf("%lld%lld",&a[i].first,&a[i].second);
m=max(m,max(a[i].first,a[i].second));
}
m<<=1;
init();
if(x!=y) sol1::work();
else sol2::work();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7908kb
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: 16ms
memory: 84936kb
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'