QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#582931#9376. GameAil_ijyqWA 88ms3628kbC++141.3kb2024-09-22 17:48:002024-09-22 17:48:00

Judging History

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

  • [2024-09-22 17:48:00]
  • 评测
  • 测评结果:WA
  • 用时:88ms
  • 内存:3628kb
  • [2024-09-22 17:48:00]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=998244353;

int qmi(int a,int b,int q)
{
    int num=1;
    while(b)
    {
        if(b&1)
            num=a*num%q;
        a=a*a%q;
        b>>=1;
    }
    return num;
}

int fun(int a,int b,int k)//1-(a/b)^k=(b^k-a^k)/b^k
{
    int t=qmi(b,k,mod);
    int res=(t-qmi(a,k,mod)+mod)%mod;
    return res* qmi(t,mod-2,mod)%mod;
}

int dfs(int x,int y,int ax,int ay)
{
    int res=0;
    if(x==0) return 0;
    if(y==0) return 1;
    if(x==y)
    {
        return ax*qmi(ax+ay,mod-2,mod)%mod;//x 赢一局的概率
    }
    if(x>y)//往右分支 b连赢
    {
        int p_next=qmi(ay*qmi(ax+ay,mod-2,mod),x/y,mod);//b连赢的概率
        res=(res+p_next*dfs(x%y,y,ax,ay)%mod+fun(ay,ax+ay,x/y))%mod;
    }
    else if(x<y)//往左分支 a连赢
    {
        int p_next=qmi(ax*qmi(ax+ay,mod-2,mod),y/x,mod); //a连赢的概率
        res=(res+p_next*dfs(x,y%x,ax,ay)%mod)%mod;//a连赢过后继续分支
    }
    return res;
}

void solve()
{
    int x,y,a0,a1,b;
    cin>>x>>y>>a0>>a1>>b;
    cout<<dfs(x,y,a0,a1)<<endl;
}

signed main()
{

    std::ios::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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
Wrong Answer
time: 88ms
memory: 3508kb

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:

7848007
419180552
612621163
36374442
592200562
45779380
870227707
169499045
86396463
415694940
46851356
252126
426243016
864656779
750317399
922456360
486881524
285134565
198191519
189360084
966510181
512645443
695650039
703100783
550002158
438470182
832829770
335852921
667870434
111027908
593590760...

result:

wrong answer 1st lines differ - expected: '947058399', found: '7848007'