QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#584463 | #9376. Game | absabs | WA | 192ms | 3716kb | C++14 | 2.3kb | 2024-09-23 14:24:38 | 2024-09-23 14:24:38 |
Judging History
answer
// #pragma GCC optimize(2)
// #pragma GCC optimize(3,"Ofrrst","inline")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define ull unsigned long long
#define ll __int128_t
#define fre freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
mt19937 rd(chrono::system_clock::now().time_since_epoch().count());
const int mod=998244353;
const int inf=0x3f3f3f3f3f3f3f3f;
const int N=2e5+10;
const double eps=1e-6;
const int hash_p1=1610612741;
const int hash_p2=805306457;
const int hash_p3=402653189;
const int base_1=131;
const int base_2=13331;
int qmi(int a,int b)
{
int res = 1;
while(b)
{
if(b & 1) res = res * a % mod;
a = a * a % mod;
b >>= 1;
}
return res;
}
int fun(int q,int cnt)
{
int res = qmi(q,cnt) % mod;
return res;
}
void solve()
{
int x,y,a,b,c,ta,tb;
cin >> x >> y >> ta >> tb >> c;
int d = __gcd(x,y);
x /= d,y /= d;
a = ta * qmi(ta + tb,mod- 2) % mod,b = tb * qmi(ta + tb,mod - 2) % mod;
int now = 1,ans = 0;
// cout << x << " " << y << endl;
// cout << a << " " << b << endl;
while(x != 1 && y != 1)
{
if(x > y)
{
int tp = x / y;
ans = (ans + now * a % mod * (1 - fun(b,tp) + mod) % mod * qmi(1 - b + mod,mod- 2) % mod) % mod;
now = now * qmi(b,tp) % mod;
x = x % y;
}
else
{
int tp = y / x;
now = now * qmi(a,tp);
y = y % x;
}
}
if(x == 1)
ans = (ans + now * qmi(a,y) % mod) % mod;
else ans = (ans + (1 - qmi(b,x) + mod) % mod * now % mod) % mod;
cout << ans << endl;
}
//#define LOCAL
signed main(){
ios
//fre
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
auto start = std::chrono::high_resolution_clock::now();
#endif
int _=1;
cin>>_;
while(_--)solve();
#ifdef LOCAL
auto end = std::chrono::high_resolution_clock::now();
cout << "Execution time: "
<< std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
<< " ms" << '\n';
#endif
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
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: 64ms
memory: 3716kb
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: 192ms
memory: 3708kb
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:
259559382 -66849961 336634076 -460430280 188152788 -773373943 -332619819 -67592229 7410460 811403241 929108133 -45748900 533360111 399832604 827385705 366394323 -737921525 -57511709 -978453616 -335010358 -78152877 -240649149 243166303 13882494 -826620615 -557962213 543915878 907565188 429251718 -795...
result:
wrong answer 1st lines differ - expected: '623291477', found: '259559382'