結果

問題 No.3682 きあいのハチマキ
コンテスト
ユーザー yaaya
提出日時 2026-09-06 00:21:07
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 32 ms / 2,000 ms
+ 752µs
コード長 4,415 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,522 ms
コンパイル使用メモリ 338,552 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-06 00:21:16
合計ジャッジ時間 3,414 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define ll long long
#define ull unsigned ll
#define ld long double
#define bl __int128_t
#define fi first
#define se second
#define vel vector<ll>
#define vvel vector<vel>
#define pll pair<ll,ll>
#define vepll vector<pll>
#define vvepll vector<vepll>
#define ves vector<string>
#define vem vector<mint>
#define vvem vector<vem>
#define pmm pair<mint,mint>
#define cleout(i) cout<<fixed<<setprecision(i)
template<class T>using PQ=priority_queue<T,vector<T>,greater<T>>;
//               上  右 下 左
vector<int> di={-1, 0, 1, 0};
vector<int> dj={ 0, 1, 0,-1};

vector<int> dx={ 0, 1, 0,-1};
vector<int> dy={ 1, 0,-1, 0};


vector<int> ddx={ 1, 1, 1, 0, -1, -1, -1, 0 };
vector<int> ddy={ 1, 0, -1, -1, -1, 0, 1, 1 };

ll inf=1000000000000000000;//1e18
// LLONG_MAX

mt19937_64 rng((ull)chrono::steady_clock::now().time_since_epoch().count());

struct mint{
    ll num;
    static ll P;
    static void set_mod(ll MOD){
        P=MOD;
    }
    mint(ll x=0){
        if(x<0){
            x*=-1;
            x%=P;
            x=P-x;
        }
        x%=P;
        num=x;
    }
    mint operator+(const mint &other)const{
        return mint(num+other.num);
    }
    mint operator-(const mint &other)const{
        return mint(num-other.num);
    }
    mint operator*(const mint &other)const{
        return mint(num*other.num);
    }
    mint &operator+=(const mint &other){
        num+=other.num;
        if(num>=P) num-=P;
        return *this;
    }
    mint &operator-=(const mint &other){
        num-=other.num;
        if(num<0) num+=P;
        return *this;
    }
    mint &operator*=(const mint &other){
        num=(num*other.num)%P;
        return *this;
    }
    mint beki(const ll &x)const{
        ll pos=x;
        mint res=1;
        mint now=num;
        while(pos){
            if(pos&1){
                res*=now;
            }
            now*=now;
            pos/=2;
        }
        return res;
    }
    mint inv()const{
        mint res=1;
        mint now=num;
        rep(i,0,30){
            if((P-2)&(1ll<<i)){
                res*=now;
            } 
            now*=now;
        }
        return res;
    }
    mint operator/(const mint &other)const{
        return *this*other.inv();
    }
    mint &operator/=(const mint &other){
        num=(num*other.inv())%P;
        return *this;
    }
    operator ll()const{
        return (ll)(num);
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.num;
        return os;
    }
    friend istream& operator>>(istream& is,mint& m){
        ll x;
        is>>x;
        m=mint(x);
        return is;
    }
};
ll mint::P=998244353;
//ll mint::P=1000000007;

void _solve(){
    ll hc,ac,sc;
    cin>>hc>>ac>>sc;
    ll hg,ag,sg;
    cin>>hg>>ag>>sg;
    ll tg=(hc+ag-1)/ag;
    ll tc=(hg+ac-1)/ac;
    tc*=-1;
    tg*=-1;
    if(sg==sc){
        if(tc>tg){
            mint pow=(mint)1/(mint)10;
            mint ans=(mint)1-pow.beki(tc-tg);
            cout<<ans+((mint)1-ans)/(mint)2<<"\n";
        }else if(tc<tg){
            mint pow=(mint)1/(mint)10;
            mint ans=(mint)1-pow.beki(tg-tc);
            cout<<((mint)1-ans)/(mint)2<<"\n";
        }else{
            cout<<(mint)1/(mint)2<<"\n";
        }
    }else if(sg>sc){
        if(tg>=tc){
            mint pow=(mint)1/(mint)10;
            mint ans=(mint)1-pow.beki(tg-tc+1);
            mint r=pow*pow;
            cout<<((mint)1-ans)*(mint)9/(mint)10/((mint)1-r)<<"\n";
        }else{
            mint pow=(mint)1/(mint)10;
            mint ans=(mint)1-pow.beki(tc-tg);
            mint r=pow*pow;
            cout<<ans+((mint)1-ans)*(mint)9/(mint)100/((mint)1-r)<<"\n";
        }
    }else{
        if(tc>=tg){
            mint pow=(mint)1/(mint)10;
            mint ans=(mint)1-pow.beki(tc-tg+1);
            mint r=pow*pow;
            cout<<ans+((mint)1-ans)*(mint)9/(mint)100/((mint)1-r)<<"\n";
        }else{
            mint pow=(mint)1/(mint)10;
            mint ans=(mint)1-pow.beki(tg-tc);
            mint r=pow*pow;
            cout<<((mint)1-ans)*(mint)9/(mint)10/((mint)1-r)<<"\n";
        }
    }
}


int main(){
    cin.tie(nullptr);
 	ios_base::sync_with_stdio(false);

    
    ll _;
    bool multitest=1;
    if(multitest)cin>>_;
    else _=1;
    rep(__,0,_){
        _solve();
    }
}
0