QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#589091#9376. GameFoedere0TL 0ms3592kbC++201.6kb2024-09-25 16:10:032024-09-25 16:10:04

Judging History

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

  • [2024-09-25 16:10:04]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3592kb
  • [2024-09-25 16:10:03]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
typedef pair<int,int> PII;
const int N=1000010;
int mod=998244353;
//priority_queue<PII> heap;
map<string,int> mp;
int n,m;
int a0,a1,b;
int x,y;
inline int read();
inline void write(int x);
int qmi(int m, int k,int p)
{
    int res = 1 % p, t = m;
    while (k)
    {
        if (k & 1)
            res = res * t % p;
        t = t * t % p;
        k >>= 1;
    }
    return res;
}
int fz=0,fm=1;
int ans=0;
int p0,p1;
void dfs(int o,int p,int t){
	if(o==p){
		int tt=t*p0%mod;
		//cout<<"  "<<tt<<endl;
		ans+=tt;
		ans%=mod;
		return;
	}
	if(o<p){
		dfs(o,p-o,t*p0%mod);
	}
	if(o>p){
		int tt=t*p0%mod;
		ans+=tt;
		ans%=mod;
		
		dfs(o-p,p,t*p1%mod);
	}
}
void solve(){
	ans=0;
	cin>>x>>y;
	cin>>a0>>a1>>b;
	b=a0+a1;
	p0=a0*qmi(b,mod-2,mod)%mod;
	p1=a1*qmi(b,mod-2,mod)%mod;
	//cout<<p0<<"  "<<p1<<endl;
	dfs(x,y,1);
	cout<<ans%mod<<endl;
	//write(fz%mod*qmi(fm,mod-2,mod)%mod);
	//puts("");
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T=1;
	cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


inline int read()
{
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9')
    {
        if (c == '-')
            f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9')
        x = (x << 3) + (x << 1) + c - '0', c = getchar();
    return x * f;
}

inline void write(int x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        write(x / 10);
    putchar('0' + x % 10);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Time 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: