結果

問題 No.3682 きあいのハチマキ
コンテスト
ユーザー テナガザル
提出日時 2026-09-05 14:53:54
言語 C++23
(gcc 15.3.0 + boost 1.92.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 58 ms / 2,000 ms
+ 43µs
コード長 1,220 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 991 ms
コンパイル使用メモリ 166,500 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 14:53:57
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long pow(long long a, long long k, long long m)
{
  long long ret = 1;
  for (a %= m; k > 0; k >>= 1, a = a * a % m) if (k & 1) ret = ret * a % m;
  return ret;
}

void solve()
{
  
}

int main()
{
  const int mod = 998244353;
  long long inv10 = pow(10, mod - 2, mod), inv2 = pow(2, mod - 2, mod), inv11 = pow(11, mod - 2, mod);
  int t;
  cin >> t;
  while (t--)
  {
    long long h[2], a[2], s[2];
    for (int i = 0; i < 2; ++i) cin >> h[i] >> a[i] >> s[i];
    long long c[2] = {(h[0] - 1) / a[1], (h[1] - 1) / a[0]};
    long long p = 1;
    long long ans = 0;
    if (c[0] > c[1])
    {
      long long tmp = 1 - inv10 + mod;
      p = 1 - pow(inv10, c[0] - c[1], mod) + mod;
      p = p * pow(tmp, mod - 2, mod) % mod * 9LL % mod * inv10 % mod;
      ans = p;
      p = pow(inv10, c[0] - c[1], mod);
    }
    else if (c[0] < c[1])
    {
      p = pow(inv10, c[1] - c[0], mod);
    }
    if (s[0] > s[1])
    {
      p = p * 10 % mod * inv11 % mod;
    }
    else if (s[0] == s[1])
    {
      p = p * inv2 % mod;
    }
    else
    {
      p = p * inv11 % mod;
    }
    ans = (ans + p) % mod;
    cout << ans << endl;
  }
}
0