結果

問題 No.1927 AB-CD
ユーザー AngrySadEightAngrySadEight
提出日時 2022-05-06 22:04:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 1,199 bytes
コンパイル時間 1,533 ms
コンパイル使用メモリ 166,516 KB
実行使用メモリ 6,180 KB
最終ジャッジ日時 2023-09-20 02:58:24
合計ジャッジ時間 3,113 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,420 KB
testcase_01 AC 5 ms
5,408 KB
testcase_02 AC 5 ms
5,716 KB
testcase_03 AC 5 ms
5,404 KB
testcase_04 AC 10 ms
5,912 KB
testcase_05 AC 10 ms
5,916 KB
testcase_06 AC 10 ms
5,780 KB
testcase_07 AC 10 ms
5,820 KB
testcase_08 AC 5 ms
5,420 KB
testcase_09 AC 11 ms
5,836 KB
testcase_10 AC 8 ms
5,712 KB
testcase_11 AC 9 ms
5,764 KB
testcase_12 AC 7 ms
5,800 KB
testcase_13 AC 8 ms
5,960 KB
testcase_14 AC 5 ms
5,404 KB
testcase_15 AC 6 ms
5,424 KB
testcase_16 AC 9 ms
5,844 KB
testcase_17 AC 8 ms
5,704 KB
testcase_18 AC 8 ms
5,724 KB
testcase_19 AC 9 ms
5,852 KB
testcase_20 AC 12 ms
5,764 KB
testcase_21 AC 10 ms
5,820 KB
testcase_22 AC 7 ms
5,680 KB
testcase_23 AC 12 ms
5,644 KB
testcase_24 AC 12 ms
6,180 KB
testcase_25 AC 12 ms
5,956 KB
testcase_26 AC 12 ms
5,904 KB
testcase_27 AC 5 ms
5,464 KB
testcase_28 AC 5 ms
5,392 KB
testcase_29 AC 5 ms
5,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
#define mod1 1000000007
#define mod2 998244353
typedef long long ll;

ll my_pow(ll x, ll n, ll mod){
    // 繰り返し二乗法.x^nをmodで割った余り.
    ll ret;
    if (n == 0){
        ret = 1;
    }
    else if (n % 2 == 1){
        ret = (x * my_pow((x * x) % mod, n / 2, mod)) % mod;
    }
    else{
        ret = my_pow((x * x) % mod, n / 2, mod);
    }
    return ret;
}

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    ll ab = 0;
    ll cd = 0;

    vector<ll> factorial(300005, 0);
    factorial[0] = 1;
    for (ll i = 0; i < 300004; i++){
        factorial[i + 1] = (factorial[i] * (i + 1)) % mod2;
    }
    for (int i = 0; i < N; i++){
        if (S[i] == 'A' || S[i] == 'B'){
            ab++;
        }
        else{
            cd++;
        }
    }
    ll ans = 1;
    ans = (ans * factorial[N]) % mod2;
    ans = (ans * my_pow(factorial[ab], mod2 - 2, mod2)) % mod2;
    ans = (ans * my_pow(factorial[cd], mod2 - 2, mod2)) % mod2;
    cout << ans << endl;
}
0