QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#582499#9376. GameChief_NingTL 0ms3680kbC++142.5kb2024-09-22 16:40:002024-09-22 16:40:00

Judging History

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

  • [2024-09-22 16:40:00]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3680kb
  • [2024-09-22 16:40:00]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define endl "\n"
#define pq priority_queue<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define debug1(x) cout<<x<<endl;
#define debug2(a,b) cout<<a<<" "<<b<<endl;
const int INF = 0x3f3f3f3f;//无穷大
const int inf = 0xc0c0c0c0;//无穷小
const int mod = 998244353.;
const int N = 1;

/*
 ________  ___  ___  ___  _______   ________ ________   ___  ________   ________
|\   ____\|\  \|\  \|\  \|\  ___ \ |\  _____\\   ___  \|\  \|\   ___  \|\   ____\
\ \  \___|\ \  \\\  \ \  \ \   __/|\ \  \__/\ \  \\ \  \ \  \ \  \\ \  \ \  \___|
 \ \  \    \ \   __  \ \  \ \  \_|/_\ \   __\\ \  \\ \  \ \  \ \  \\ \  \ \  \  ___
  \ \  \____\ \  \ \  \ \  \ \  \_|\ \ \  \_| \ \  \\ \  \ \  \ \  \\ \  \ \  \|\  \
   \ \_______\ \__\ \__\ \__\ \_______\ \__\   \ \__\\ \__\ \__\ \__\\ \__\ \_______\
    \|_______|\|__|\|__|\|__|\|_______|\|__|    \|__| \|__|\|__|\|__| \|__|\|_______|
                                                                                     */
ll fpm(ll a,ll b) {
    a%=mod;
    ll ans = 1;
    while (b) {
        if (b & 1)
            ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }
    return ans;
}
ll inv(int x){
    return fpm(x,mod-2);
}

void ChiefNing()
{
    int x,y;
    cin>>x>>y;
    int a,b,c;
    cin>>a>>b>>c;
    int pa=a*inv(a+b)%mod,pb=b*inv(a+b)%mod;
    if(x==y){
        cout<<pa<<endl;
        return ;
    }
    int ans=0,now=1;
    bool is=0;//表示是否第一次达到
    int k1=0,k2=0;
    while(x!=y){
        if(x<y){
            k1++;
            if(is){
                now*=pa;
                now%=mod;
                ans+=((now*pa)%mod);
                ans%=mod;
            }
            else{
                now*=pa;
                now%=mod;
            }
            y-=x;
        }
        else{
            if(!is){
                ans+=((now*pa)%mod);
                ans%=mod;
            }//此时是第一次满足,那么需要乘一下当前值
            k2++;
            is=1;
            now*=pb;
            now%=mod;
            ans+=((now*pa)%mod);
            ans%=mod;
            x-=y;
        }
    }
    if(!is)ans+=((now*pa)%mod);
    cout<<ans%mod<<endl;
}


signed main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int _;
    cin>>_;
    while(_--)
        ChiefNing();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: