QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423205#2834. NonsenseTianTian2008WA 1ms7980kbC++141.4kb2024-05-27 21:32:072024-05-27 21:32:07

Judging History

你现在查看的是最新测评结果

  • [2024-05-27 21:32:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7980kb
  • [2024-05-27 21:32:07]
  • 提交

answer

#include <iostream>
#include <cstdio>
#define mod 998244353
using namespace std;
typedef long long ll;
ll n,m,x,y,q,fac[5010],inv[5010],px[5010],py[5010];
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+1;++i) fac[i]=fac[i-1]*(n-i+2)%mod;
	ll pro=1;
	for(int i=1;i<=m+1;++i) pro=pro*i%mod;
	inv[m+1]=ksm(pro,mod-2);
	for(int i=m+1;i>=1;--i) inv[i-1]=inv[i]*i%mod;
	px[m]=ksm(x,n-m);
	for(int i=m;i>=1;--i) px[i-1]=px[i]*x%mod;
	py[m]=ksm(y,n-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-1]%mod;
				else f[i][j]=-f[i-1][j];
				if(j==0) f[i][j]+=binom(i)*px[i-1]%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",px[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: 0
Wrong Answer
time: 1ms
memory: 7980kb

input:

3 1 2 2
1 1
1 2
100 2 3 1
1 1

output:

36
998244309
806263209

result:

wrong answer 1st lines differ - expected: '6', found: '36'