結果

問題 No.3099 Parentheses Decomposition
ユーザー sai
提出日時 2025-04-11 21:28:52
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 3,763 ms
コンパイル使用メモリ 276,880 KB
実行使用メモリ 7,876 KB
最終ジャッジ日時 2025-04-11 21:28:59
合計ジャッジ時間 6,412 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;

mint Fac[505050], Finv[505050];

mint Com(int a, int b) {
  if (a < b) {
    return 0;
  }
  return Fac[a] * Finv[b] * Finv[a - b];
}

void init() {
  Fac[0] = 1;
  for (int i = 1; i < 505050; i++) {
    Fac[i] = i * Fac[i - 1];
  }
  for (int i = 0; i < 505050; i++) {
    Finv[i] = Fac[i].inv();
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  init();
  int n;
  std::string s;
  std::cin >> n >> s;
  mint ans = 0;
  if (s[0] == s[1]) {// A
    for (int k = 0; k <= n / 2; k++) {
      ans += Com(n / 2, k) * Com(n / 2, k);
    }
  } else {// B
    for (int k = 0; k <= n / 2; k++) {
      ans += Com(n / 2, k);
    }
  }
  std::cout << ans.val() << '\n';
}
0