QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#581365#9376. GamejayketWA 172ms3700kbC++231.9kb2024-09-22 12:18:442024-09-22 12:18:44

Judging History

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

  • [2024-09-22 12:18:44]
  • 评测
  • 测评结果:WA
  • 用时:172ms
  • 内存:3700kb
  • [2024-09-22 12:18:44]
  • 提交

answer

#include<bits/stdc++.h>

using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f64 = long double;
using i128 = __int128_t;
using f128 = __float128;

#ifndef ONLINE_JUDGE
#include "algo/debug.hpp"
#else
#define debug(...) (void)42
#endif

template<class T>
constexpr void chmax(T& x, T y) {
	if (y > x) {
		x = y;
	}
}

template<class T>
constexpr void chmin(T& x, T y) {
	if (y < x) {
		x = y;
	}
}

#define int i64

constexpr int Mod = 998244353;

constexpr int mul(int a, int b) {
	return (i64(a) * b) % Mod;
}

constexpr int add(int a, int b) {
	return (i64(a) + b) % Mod;
}

constexpr int power(int a, int b) {
	int res = 1;
	for (; b != 0; b >>= 1, a = mul(a, a)) {
		if (b & 1) {
			res = mul(res, a);
		}
	}
	return res;
}

constexpr int inv(int x) {
	return power(x, Mod - 2);
}

auto main() ->int32_t {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	std::cout << std::fixed << std::setprecision(13);

	auto solve = [&]() {
		int x, y;
		std::cin >> x >> y;

		int a0, a1, b;
		std::cin >> a0 >> a1 >> b;

		auto Get = [&](int q, int n) {
			int up = mul(q, add(1, Mod - power(q, n)));
			int dn = add(1, Mod - q);
			return mul(up, inv(dn));
		};

		int p0 = mul(a0 , inv(add(a0, a1)));
		int p1 = mul(a1, inv(add(a0, a1)));
		int ans = 1;

		if (x == y) {
			std::cout << p0 << '\n';
			return ;
		}

		while (x > 0 and y > 0) {
			if (x > y) {
				int cnt = (x + y - 1) / y - 1;
				ans = mul(ans, add(p0, mul(p0, Get(p1, cnt))));
				x -= 1LL * y * cnt;
				if (x == y)break;
			} else if (x < y) {
				int cnt = (y + x - 1) / x - 1;
				ans = mul(ans, power(p0, cnt));
				y -= 1LL * x * cnt;
			} else {
				ans = mul(ans, p0);
				break;
			}
		}

		std::cout << ans << '\n';
	};

	int t;
	std::cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 49ms
memory: 3572kb

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:

947058399
376449942
612621163
138416357
592200562
45779380
870227707
169499045
86396463
415694940
46851356
951368934
426243016
864656779
750317399
922456360
486881524
824329239
198191519
189360084
966510181
512645443
695650039
703100783
550002158
438470182
246877045
39876086
667870434
405196653
5935...

result:

ok 100000 lines

Test #3:

score: -100
Wrong Answer
time: 172ms
memory: 3700kb

input:

100000
167959139 481199252
18199423 25950409 149762920
773386884 579721198
16629525 28339910 152155823
2087506 268792718
43528658 6471925 90197530
691952768 717268783
516613092 94328992 743662288
45277106 856168102
309821265 346013425 963168258
279198849 527268921
30167950 166388455 577970339
140515...

output:

338166565
411984712
578545761
346013585
675118121
450137099
189880238
563642154
250010983
804224972
367640834
226071501
145572379
123252626
541286560
505219514
550957526
901293614
750014026
88017718
260498363
996148270
662670643
205215474
145170592
785083785
200461995
203320858
438996238
347473926
2...

result:

wrong answer 1st lines differ - expected: '623291477', found: '338166565'