QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#583157#9376. Gameucup-team3712TL 0ms3560kbC++202.2kb2024-09-22 18:40:062024-09-22 18:40:06

Judging History

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

  • [2024-09-22 18:40:06]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3560kb
  • [2024-09-22 18:40:06]
  • 提交

answer

//在决定放弃以前多写一点题吧~
//just solve more problems before giving up

//created: 2024-09-21 19:11:29
// #define SKADI
#if defined(YUANSHEN)
#include<D:/Tovi/template/my_template.hpp>
#else
#include<bits/stdc++.h>
using namespace std;
#endif
#ifndef SKADI
#define dbg(...) 42
#endif
template <typename T1, typename T2> void cmin(T1 &x, const T2 &y) {
x = x < y ? x : y;
}
template <typename T1, typename T2> void cmax(T1 &x, const T2 &y) {
x = x > y ? x : y;
}
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
#define fixset(x) fixed<<setprecision(x)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define ALL(x) (x).begin()+1,(x).end()
#define see "\n*********C-O-D-E-F-O-R-C-E-S**********\n"
const int INF = 1000000000;
const ll LNF = 1000000000000000000;
const int mod = 998244353;
ll a0,a1,B,ans;
ll ksm(ll x,ll y)
{
    ll res=1;
    x%=mod;
    while(y){
        if(y&1) res=res*x%mod;
        x=x*x%mod;
        y>>=1;
    }
    return res;
}
ll inv(ll x)
{
    return ksm(x,mod-2);
}

ll calc(ll x,ll y)
{
    ll res=1;
    res*=ksm(a0*B,x)*ksm(a1*B,y)%mod;
    return res;
}
void dfs(ll x,ll y,ll a,ll b)
{
    // cerr<<x<<" "<<y<<" "<<a<<" "<<b<<'\n';
    if(x==y){
        // ans+=a0*B%mod;
        ans+=calc(a+1,b);
        ans%=mod;
        // cerr<<a0<<" "<<B<<'\n';
        // cerr<<a0*b<<'\n';
        return;
    }
    if(x<y){
        dfs(x,y-x,a+1,b);
    }
    if(x>y){
        ans+=calc(a+1,b);
        dfs(x-y,y,a,b+1);
    }
}
void solve()
{
    ll x,y;
    cin>>x>>y>>a0>>a1>>B;
    int g=__gcd(a0,a1);
    a0/=g,a1/=g;
    B=inv(a0+a1);
    // if(a0==a1){
    //     cout<<b<<'\n';
    //     return;
    // }
    ans=0;
    dfs(x,y,0,0);
    cout<<ans<<'\n';
    // cout<<calc(1,0)<<'\n';
    // vis.clear();
}

int main()
{
#ifndef SKADI
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#endif
    // dbg(calc(2,0));
    // a0=1,a1=1,b=inv(2);
    // ll x=calc(1,0);

    // dbg(x);
    int T=1;
    cin>>T;
    while(T--)
        solve();
    return 0;
}
/*
10 2
8 4
*/

详细

Test #1:

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

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: