結果

問題 No.1927 AB-CD
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-18 00:07:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 1,092 bytes
コンパイル時間 1,108 ms
コンパイル使用メモリ 107,396 KB
実行使用メモリ 19,580 KB
最終ジャッジ日時 2023-08-22 01:20:07
合計ジャッジ時間 4,095 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
18,492 KB
testcase_01 AC 18 ms
18,312 KB
testcase_02 AC 17 ms
18,484 KB
testcase_03 AC 17 ms
18,748 KB
testcase_04 AC 23 ms
19,180 KB
testcase_05 AC 22 ms
19,184 KB
testcase_06 AC 22 ms
19,172 KB
testcase_07 AC 22 ms
19,076 KB
testcase_08 AC 18 ms
18,908 KB
testcase_09 AC 23 ms
19,068 KB
testcase_10 AC 21 ms
19,040 KB
testcase_11 AC 22 ms
19,040 KB
testcase_12 AC 20 ms
18,928 KB
testcase_13 AC 20 ms
19,008 KB
testcase_14 AC 18 ms
18,680 KB
testcase_15 AC 18 ms
18,976 KB
testcase_16 AC 23 ms
19,360 KB
testcase_17 AC 22 ms
19,128 KB
testcase_18 AC 21 ms
19,124 KB
testcase_19 AC 22 ms
19,104 KB
testcase_20 AC 24 ms
19,308 KB
testcase_21 AC 21 ms
19,048 KB
testcase_22 AC 19 ms
18,924 KB
testcase_23 AC 23 ms
19,364 KB
testcase_24 AC 25 ms
19,316 KB
testcase_25 AC 24 ms
19,580 KB
testcase_26 AC 25 ms
19,360 KB
testcase_27 AC 18 ms
18,516 KB
testcase_28 AC 17 ms
18,372 KB
testcase_29 AC 17 ms
18,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>

using namespace std;

using ll = long long;
const long long modc=998244353, MAX=1000000;
vector<long long> f, finv;

long long inv(long long x){
    long long ans = 1, e = modc-2;
    x %= modc;

    while (e > 0){
        if ((e & 1LL)) ans = (ans * x) % modc;
        e = e >> 1LL;
        x = (x*x) % modc;
    }

    return ans;
}

void init(){
    f.resize(MAX+1); finv.resize(MAX+1);
    f[0] = 1;
    for (int i=1; i<=MAX; i++) f[i] = (f[i-1]*i) % modc;
    finv[MAX] = inv(f[MAX]);
    for (int i=MAX-1; i>=0; i--) finv[i] = (finv[i+1] * (i+1)) % modc;
}

long long C(long long n, long long k){ 
    if (n < k || k < 0) return 0;

    return (((f[n] * finv[k]) % modc) * finv[n-k]) % modc;
}

int main(){

    init();
    ll N, a=0, b=0;
    string S;
    cin >> N >> S;
    for (auto x : S){
        if (x == 'A' || x == 'B') a++;
        else b++;
    }

    cout << C(a+b, a) << endl;

    return 0;
}
0