QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586076#9376. Gamedaniel14311531ML 0ms3704kbC++20638b2024-09-24 01:02:132024-09-24 01:02:14

Judging History

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

  • [2024-09-24 01:02:14]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3704kb
  • [2024-09-24 01:02:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
int p1, p2;

int inv(int x) {
	if(x <= 1) return 1;
	return 1ll * (mod - mod / x) * inv(mod % x) % mod;
}
int calc(int x, int y) {
	if(y <= 0) return 1;
	if(x <= 0) return 0;
	return (1ll * p1 * calc(x, y - x) + 1ll * p2 * calc(x - y, y)) % mod;
}
int main() {
	ios::sync_with_stdio(0); cin.tie(nullptr);
	int T; cin >> T;
	for(; T; --T) {
		int x, y, s; cin >> x >> y;
		cin >> p1 >> p2 >> s; s = p1 + p2;
		p1 = 1ll * p1 * inv(s) % mod;
		p2 = 1ll * p2 * inv(s) % mod;
		cout << calc(x, y) << "\n";
	}	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3704kb

input:

3
1 1
2 2 6
1 3
2 3 6
3 4
7 3 15

output:

499122177
910398850
220911476

result:

ok 3 lines

Test #2:

score: -100
Memory Limit Exceeded

input:

100000
1 1000000000
12980050 128257807 266126484
1 1000000000
400255084 123438563 768881284
1000000000 1000000000
24563487 72082135 450057094
1 1000000000
56952077 40876000 193815114
1000000000 1000000000
82048274 239365585 326520865
1000000000 1
309821265 346013425 963168258
1 1
104158269 199365020...

output:


result: