結果

問題 No.1927 AB-CD
ユーザー titan23titan23
提出日時 2022-07-03 03:21:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 158 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 137,384 KB
最終ジャッジ日時 2023-08-18 22:30:26
合計ジャッジ時間 6,286 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,128 KB
testcase_01 AC 74 ms
71,152 KB
testcase_02 AC 74 ms
71,132 KB
testcase_03 AC 79 ms
71,392 KB
testcase_04 AC 143 ms
123,784 KB
testcase_05 AC 140 ms
123,160 KB
testcase_06 AC 134 ms
118,516 KB
testcase_07 AC 132 ms
117,536 KB
testcase_08 AC 84 ms
76,672 KB
testcase_09 AC 140 ms
123,636 KB
testcase_10 AC 126 ms
112,656 KB
testcase_11 AC 131 ms
117,860 KB
testcase_12 AC 98 ms
94,452 KB
testcase_13 AC 106 ms
97,368 KB
testcase_14 AC 79 ms
75,636 KB
testcase_15 AC 88 ms
83,612 KB
testcase_16 AC 131 ms
117,796 KB
testcase_17 AC 120 ms
107,948 KB
testcase_18 AC 122 ms
108,396 KB
testcase_19 AC 124 ms
112,604 KB
testcase_20 AC 144 ms
129,820 KB
testcase_21 AC 125 ms
112,876 KB
testcase_22 AC 96 ms
89,932 KB
testcase_23 AC 146 ms
130,420 KB
testcase_24 AC 158 ms
137,384 KB
testcase_25 AC 156 ms
137,240 KB
testcase_26 AC 155 ms
137,340 KB
testcase_27 AC 73 ms
71,252 KB
testcase_28 AC 74 ms
71,292 KB
testcase_29 AC 74 ms
71,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
mod = 998244353

class Mod_Comb:
  def __init__(self, limit: int, mod: int):
    "O(limit)"
    # limit: limit C r.
    # if n is too large: limit = -1 and use ncr_2.
    # mod: prime.

    self.limit = limit
    self.mod = mod

    self.fact = [1, 1]
    self.factinv = [1, 1]
    self.inv = [0, 1]

    for i in range(2, self.limit+1):
      self.fact.append((self.fact[-1]*i % self.mod))
      self.inv.append((-self.inv[self.mod%i] * (self.mod // i)) % self.mod)
      self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.mod)

  def div_mod(self, a: int, b: int) -> int:
    "Return (a // b % mod), mod:prime"
    if (a % b == 0):
      return a // b
    return (a % self.mod) * pow(b, self.mod-2, self.mod) % self.mod

  def ncr(self, n: int, r: int) -> int:
    "Return (nCr % mod)"
    "O(1), N <= 10**7"
    if r < 0 or n < r:
      return 0
    r = min(r, n-r)
    return self.fact[n] * self.factinv[r] * self.factinv[n-r] % self.mod

  def ncr_2(self, n: int, r: int) -> int:
    "O(r)"
    ret = 1
    r = min(r, n-r)
    for i in range(r):
      ret *= n - i
      ret %= self.mod
    for i in range(1, r+1):
      ret = self.div_mod(ret, i)
    return ret

#  -----------------------  #

n = int(input())
s = input()
cnt = s.count('A') + s.count('B')

mc = Mod_Comb(n, mod)
ans = mc.ncr(n, cnt)
print(ans)
0