結果

問題 No.1927 AB-CD
ユーザー ぷらぷら
提出日時 2022-05-06 21:26:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 815 bytes
コンパイル時間 2,054 ms
コンパイル使用メモリ 200,364 KB
実行使用メモリ 50,624 KB
最終ジャッジ日時 2023-09-20 02:14:25
合計ジャッジ時間 4,661 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
50,460 KB
testcase_01 AC 42 ms
50,344 KB
testcase_02 AC 44 ms
50,220 KB
testcase_03 AC 43 ms
50,268 KB
testcase_04 AC 48 ms
50,360 KB
testcase_05 AC 45 ms
50,344 KB
testcase_06 AC 49 ms
50,404 KB
testcase_07 AC 47 ms
50,344 KB
testcase_08 AC 44 ms
50,328 KB
testcase_09 AC 46 ms
50,348 KB
testcase_10 AC 46 ms
50,544 KB
testcase_11 AC 45 ms
50,544 KB
testcase_12 AC 46 ms
50,344 KB
testcase_13 AC 45 ms
50,472 KB
testcase_14 AC 45 ms
50,368 KB
testcase_15 AC 43 ms
50,404 KB
testcase_16 AC 49 ms
50,468 KB
testcase_17 AC 45 ms
50,624 KB
testcase_18 AC 48 ms
50,340 KB
testcase_19 AC 44 ms
50,348 KB
testcase_20 AC 47 ms
50,356 KB
testcase_21 AC 46 ms
50,548 KB
testcase_22 AC 45 ms
50,404 KB
testcase_23 AC 48 ms
50,540 KB
testcase_24 AC 50 ms
50,456 KB
testcase_25 AC 48 ms
50,416 KB
testcase_26 AC 51 ms
50,540 KB
testcase_27 AC 44 ms
50,272 KB
testcase_28 AC 44 ms
50,220 KB
testcase_29 AC 41 ms
50,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long fac[2000005], finv[2000005], inv[2000005];

void COMinit() {
    fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1;
    for (int i = 2; i < 2000005; i++) {
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    COMinit();
    int a = 0,c = 0;
    for(int i = 0; i < N; i++) {
        if(S[i] == 'A' || S[i] == 'B') {
            a++;
        }
        else {
            c++;
        }
    }
    cout << COM(N,a) << endl;
}
0