結果

問題 No.3682 きあいのハチマキ
コンテスト
ユーザー iastm
提出日時 2026-09-06 22:42:41
言語 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  
実行時間 14 ms / 2,000 ms
+ 66µs
コード長 1,136 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 974 ms
コンパイル使用メモリ 164,464 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-06 22:42:46
合計ジャッジ時間 2,119 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <atcoder/modint>

using mint = atcoder::modint998244353;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int T;
    std::cin >> T;
    mint inv2 = mint(2).inv();
    mint inv10 = mint(10).inv();
    mint inv11 = mint(11).inv();
    while (T--) {
        int64_t hc, ac, sc, hg, ag, sg;
        std::cin >> hc >> ac >> sc >> hg >> ag >> sg;
        int64_t t = std::min((hc + ag - 1) / ag, (hg + ac - 1) / ac) - 1;
        hc -= t * ag;
        hg -= t * ac;
        int64_t tc = (hc + ag - 1) / ag - 1;
        int64_t tg = (hg + ac - 1) / ac - 1;
        bool rev = sc < sg || sc == sg && tc < tg;
        if (rev) std::swap(hc, hg), std::swap(ac, ag), std::swap(sc, sg), std::swap(tc, tg);
        mint result = sc != sg ? 1 - inv11 : inv2;
        mint mod = 1, sub = 0;
        if (tc > 0) {
            mod = inv10.pow(tc);
            sub = 1 - mod;
        } else if (tg > 0) {
            mod = inv10.pow(tg);
        }
        result = result * mod + sub;
        if (rev) result = 1 - result;
        std::cout << result.val() << '\n';
    }
}
0