結果
| 問題 |
No.1927 AB-CD
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:33:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 53 ms / 2,000 ms |
| コード長 | 712 bytes |
| コンパイル時間 | 206 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 67,016 KB |
| 最終ジャッジ日時 | 2025-03-20 20:34:41 |
| 合計ジャッジ時間 | 2,763 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
MOD = 998244353
n = int(input())
s = input().strip()
a = s.count('A')
b = s.count('B')
c_count = s.count('C')
d_count = s.count('D')
ab_count = a + b
cd_count = c_count + d_count
if ab_count > 0 and cd_count > 0:
max_n = n
fact = [1] * (max_n + 1)
for i in range(1, max_n + 1):
fact[i] = fact[i-1] * i % MOD
inv_fact = [1] * (max_n + 1)
inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD)
for i in range(max_n - 1, -1, -1):
inv_fact[i] = inv_fact[i+1] * (i+1) % MOD
def comb(n, k):
if k < 0 or k > n:
return 0
return fact[n] * inv_fact[k] % MOD * inv_fact[n - k] % MOD
ans = comb(n, ab_count)
else:
ans = 1
print(ans)
lam6er