結果

問題 No.1927 AB-CD
ユーザー siganaisiganai
提出日時 2022-05-06 22:40:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 86,784 KB
実行使用メモリ 142,004 KB
最終ジャッジ日時 2023-09-20 03:45:59
合計ジャッジ時間 8,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 229 ms
141,108 KB
testcase_01 AC 230 ms
141,368 KB
testcase_02 AC 224 ms
141,332 KB
testcase_03 AC 224 ms
141,084 KB
testcase_04 AC 238 ms
141,684 KB
testcase_05 AC 235 ms
141,616 KB
testcase_06 AC 240 ms
141,676 KB
testcase_07 AC 233 ms
141,284 KB
testcase_08 AC 233 ms
141,216 KB
testcase_09 AC 233 ms
141,648 KB
testcase_10 AC 236 ms
141,528 KB
testcase_11 AC 234 ms
141,604 KB
testcase_12 AC 230 ms
141,216 KB
testcase_13 AC 229 ms
141,028 KB
testcase_14 AC 233 ms
141,420 KB
testcase_15 AC 231 ms
141,300 KB
testcase_16 AC 237 ms
141,804 KB
testcase_17 AC 234 ms
141,544 KB
testcase_18 AC 238 ms
141,396 KB
testcase_19 AC 238 ms
141,624 KB
testcase_20 AC 236 ms
141,568 KB
testcase_21 AC 233 ms
141,476 KB
testcase_22 AC 231 ms
141,064 KB
testcase_23 AC 236 ms
141,732 KB
testcase_24 AC 234 ms
142,004 KB
testcase_25 AC 235 ms
141,948 KB
testcase_26 AC 239 ms
141,860 KB
testcase_27 AC 225 ms
141,132 KB
testcase_28 AC 226 ms
141,092 KB
testcase_29 AC 224 ms
141,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
from heapq import *
import functools
mod=998244353

import sys
input=sys.stdin.readline
#nCrをmodで割ったあまりを求める
def cmb(n, r):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] % mod * g2[n-r] % mod

N = 3 * 10 ** 5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
n = int(input())
s = input().rstrip()
ab = 0
cd = 0
for i in range(n):
    if s[i] == 'A' or s[i] == 'B':
        ab += 1
    else:
        cd += 1
ans = cmb(ab+cd,cd)
print(ans)
0