結果

問題 No.1927 AB-CD
ユーザー asaringoasaringo
提出日時 2022-05-06 21:49:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,760 bytes
コンパイル時間 2,263 ms
コンパイル使用メモリ 198,824 KB
実行使用メモリ 11,732 KB
最終ジャッジ日時 2023-09-20 02:40:51
合計ジャッジ時間 6,215 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
11,208 KB
testcase_01 AC 89 ms
11,136 KB
testcase_02 AC 89 ms
11,308 KB
testcase_03 AC 89 ms
11,152 KB
testcase_04 AC 92 ms
11,328 KB
testcase_05 AC 92 ms
11,348 KB
testcase_06 AC 92 ms
11,264 KB
testcase_07 AC 91 ms
11,392 KB
testcase_08 AC 89 ms
11,432 KB
testcase_09 AC 92 ms
11,440 KB
testcase_10 AC 92 ms
11,484 KB
testcase_11 AC 92 ms
11,504 KB
testcase_12 AC 90 ms
11,264 KB
testcase_13 AC 91 ms
11,280 KB
testcase_14 AC 89 ms
11,308 KB
testcase_15 AC 89 ms
11,424 KB
testcase_16 AC 92 ms
11,276 KB
testcase_17 AC 91 ms
11,412 KB
testcase_18 AC 91 ms
11,332 KB
testcase_19 AC 91 ms
11,332 KB
testcase_20 AC 92 ms
11,372 KB
testcase_21 AC 91 ms
11,260 KB
testcase_22 AC 90 ms
11,280 KB
testcase_23 AC 92 ms
11,732 KB
testcase_24 AC 93 ms
11,564 KB
testcase_25 AC 93 ms
11,548 KB
testcase_26 AC 93 ms
11,484 KB
testcase_27 AC 89 ms
11,408 KB
testcase_28 AC 89 ms
11,308 KB
testcase_29 AC 89 ms
11,152 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std ;
#define fast_input_output ios::sync_with_stdio(false); cin.tie(nullptr);
typedef long long ll ;
typedef long double ld ;
typedef pair<ll,ll> P ;
typedef tuple<ll,ll,ll> TP ;
#define chmin(a,b) a = min(a,b)
#define chmax(a,b) a = max(a,b)
#define bit_count(x) __builtin_popcountll(x)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / gcd(a,b) * b
#define rep(i,n) for(int i = 0 ; i < n ; i++)
#define rrep(i,a,b) for(int i = a ; i < b ; i++)
#define endl "\n"

const int mod = 998244353 ;
const int MAX_N = 505050 ;

int n ;
string S ;

ll inv[MAX_N+1] ; // (n!)^(p-2) (mod p) を格納
ll fac[MAX_N+1] ; // (n!) (mod p) を格納

ll powmod(ll x , ll n){
    ll res = 1 ;
    while(n > 0){
        if(n & 1) (res *= x) %= mod ;
        (x *= x) %= mod ;
        n >>= 1 ;
    }
    return res ;
}

// 階乗の逆元(n!)^(-1)のmodを配列に格納
void f(){
    inv[0] = 1 ; inv[1] = 1 ;
    for(ll i = 2 ; i <= MAX_N ; i++){
        inv[i] = powmod(i,mod-2) * inv[i-1] % mod ;
    }
}

// 階乗のmodを配列に格納
void g(){
    fac[0] = 1 ; fac[1] = 1 ;
    for(ll i = 2 ; i <= MAX_N ; i++){
        fac[i] = (fac[i-1] * i) % mod ;
    }
}

//nCrの計算
ll combination(ll n , ll r){
    if(n < 0 || r < 0 || n < r) return 0 ;
    return fac[n] * inv[n-r] % mod * inv[r] % mod ;
}

ll permutation(ll n , ll r){
    if(n < 0 || r < 0 || n < r) return 0 ;
    return fac[n] * inv[n-r] % mod ;
}

void init(){ f() ; g() ; }

int main(){
    fast_input_output
    init() ;
    cin >> n >> S ;
    int ab = 0 , cd = 0 ;
    rep(i,n){
        if(S[i] == 'A') ab++ ;
        if(S[i] == 'B') ab++ ;
        if(S[i] == 'C') cd++ ;
        if(S[i] == 'D') cd++ ;
    }
    cout << combination(ab+cd,cd) << endl ;
}
0