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