結果

問題 No.1927 AB-CD
ユーザー 👑 H20H20
提出日時 2022-05-06 21:48:53
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 87,072 KB
実行使用メモリ 138,164 KB
最終ジャッジ日時 2023-09-20 02:40:07
合計ジャッジ時間 5,152 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,328 KB
testcase_01 AC 73 ms
71,384 KB
testcase_02 AC 74 ms
71,144 KB
testcase_03 AC 74 ms
71,276 KB
testcase_04 AC 132 ms
124,152 KB
testcase_05 AC 130 ms
123,852 KB
testcase_06 AC 124 ms
118,628 KB
testcase_07 AC 121 ms
118,428 KB
testcase_08 AC 79 ms
77,248 KB
testcase_09 AC 129 ms
124,380 KB
testcase_10 AC 119 ms
113,068 KB
testcase_11 AC 124 ms
118,344 KB
testcase_12 AC 98 ms
94,924 KB
testcase_13 AC 102 ms
97,808 KB
testcase_14 AC 78 ms
76,404 KB
testcase_15 AC 86 ms
83,756 KB
testcase_16 AC 121 ms
118,544 KB
testcase_17 AC 110 ms
108,480 KB
testcase_18 AC 112 ms
108,940 KB
testcase_19 AC 119 ms
113,372 KB
testcase_20 AC 138 ms
130,432 KB
testcase_21 AC 119 ms
113,296 KB
testcase_22 AC 92 ms
90,388 KB
testcase_23 AC 136 ms
130,796 KB
testcase_24 AC 144 ms
137,968 KB
testcase_25 AC 145 ms
137,976 KB
testcase_26 AC 143 ms
138,164 KB
testcase_27 AC 72 ms
71,448 KB
testcase_28 AC 72 ms
71,636 KB
testcase_29 AC 73 ms
71,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#コンビネーション
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 998244353
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル



N = int(input())
S = input()
AB = S.count('A')+S.count('B')
CD = S.count('C')+S.count('D')

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 )




print(g1[N]*g2[AB]*g2[CD]%mod)
0