結果

問題 No.2872 Depth of the Parentheses
ユーザー haihamabossu
提出日時 2024-09-06 22:37:15
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 954 bytes
コンパイル時間 2,266 ms
コンパイル使用メモリ 204,164 KB
最終ジャッジ日時 2025-02-24 04:37:05
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21 WA * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using mint = atcoder::modint998244353;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

void solve() {
  ll x, k;
  cin >> x >> k;
  if (x == 0 || x == 100) {
    cout << "0\n";
    return;
  }
  vector dp(30, vector<mint>(30, 0));
  mint p = mint(x) * mint(100).inv(), q = mint(100 - x) * mint(100).inv();
  dp[1][1] = 1;
  rep(ki, k * 2) {
    vector nex(30, vector<mint>(30, 0));
    nex[0] = dp[0];
    for (ll cd = 1; cd < 25; cd++) {
      for (ll md = cd; md < 25; md++) {
        nex[cd + 1][max(cd + 1, md)] += dp[cd][md] * p;
        nex[cd - 1][md] += dp[cd][md] * q;
      }
    }
    swap(dp, nex);
  }
  mint ans;
  rep(md, 25) ans += dp[1][md + 1] * md;
  cout << ans.val() << '\n';
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  int T = 1;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
0