QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#423259#2834. NonsenseDaiRuiChen007WA 217ms199188kbC++141.2kb2024-05-27 21:54:502024-05-27 21:54:51

Judging History

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

  • [2024-05-27 21:54:51]
  • 评测
  • 测评结果:WA
  • 用时:217ms
  • 内存:199188kb
  • [2024-05-27 21:54:50]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN=5005,MAXQ=2e5+5,MOD=998244353;
ll ksm(ll a,ll b=MOD-2,ll p=MOD) {
	if(b<0) b+=MOD-1;
	ll ret=1;
	for(;b;a=a*a%p,b>>=1) if(b&1) ret=ret*a%p;
	return ret;
}
int n,q,s,t,m=0;
int a[MAXQ],b[MAXQ];
ll f[MAXN][MAXN],C[MAXN<<1];
void solve() {
	m=0;
	for(int i=1;i<=q;++i) cin>>a[i]>>b[i],m=max({m,a[i],b[i]});
	if(s==t) {
		C[0]=1;
		for(int i=1;i<=min(2*m,n);++i) {
			C[i]=C[i-1]*(n-i+1)%MOD*ksm(i)%MOD;
		}
		for(int i=1;i<=q;++i) cout<<(ksm(s,n-a[i]-b[i])*C[a[i]+b[i]]%MOD)<<"\n";
		return ;
	}
	C[0]=1;
	for(int i=1;i<=m;++i) {
		C[i]=C[i-1]*(n-i+2)%MOD*ksm(i)%MOD;
	}
	for(int i=0;i<=m;++i) for(int j=0;j<=m;++j) f[i][j]=0;
	for(int i=0;i<=m;++i) {
		f[i][0]=(f[i][0]+C[i]*ksm(s,n+1-i))%MOD;
		f[0][i]=(f[0][i]-C[i]*ksm(t,n+1-i))%MOD;
		if(f[0][i]<0) f[0][i]+=MOD;
	}
	int w=ksm((s+MOD-t)%MOD);
	for(int i=0;i<=m;++i) for(int j=0;j<=m;++j) {
		if(i) f[i][j]=(f[i][j]+MOD-f[i-1][j])%MOD;
		if(j) f[i][j]=(f[i][j]+f[i][j-1])%MOD;
		f[i][j]=f[i][j]*w%MOD;
	}
	for(int i=1;i<=q;++i) cout<<f[a[i]][b[i]]<<"\n";
}
signed main() {
	ios::sync_with_stdio(false);
	while(cin>>n>>s>>t>>q) solve();
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 7804kb

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: 0
Accepted
time: 9ms
memory: 46660kb

input:

1000000000 0 1 1
1000 1000
2 0 0 1
1 1
2 998244352 998244352 1
1 1

output:

381781645
1
1

result:

ok 3 lines

Test #3:

score: 0
Accepted
time: 217ms
memory: 199188kb

input:

1000000000 998244351 998244352 1
5000 5000

output:

663228915

result:

ok single line: '663228915'

Test #4:

score: -100
Wrong Answer
time: 26ms
memory: 5672kb

input:

105886041 9 3 200
4 3
5 1
1 1
4 1
3 3
1 5
2 1
1 5
2 1
1 5
3 3
4 4
2 1
4 4
1 2
5 2
5 2
2 5
4 5
3 3
4 3
1 4
3 1
5 4
5 3
5 2
5 3
3 3
1 3
4 3
2 3
3 5
1 3
3 5
2 3
4 4
3 4
5 5
2 3
1 1
3 3
4 2
1 4
4 5
2 3
1 5
2 2
4 2
5 5
2 1
4 3
3 3
3 1
2 1
2 5
1 1
4 4
1 5
1 5
3 1
3 2
2 2
4 1
5 5
3 4
2 2
2 1
5 3
5 3
2 2
1 ...

output:

721440251
764408668
442427888
914530150
115811774
360614503
666106268
360614503
666106268
360614503
115811774
166867820
666106268
166867820
985976063
717651702
717651702
405340273
435048189
115811774
721440251
719754512
660548079
998056822
165742634
717651702
165742634
115811774
407319461
721440251
...

result:

wrong answer 601st lines differ - expected: '693360471', found: '589969110'