結果

問題 No.1927 AB-CD
ユーザー kokatsukokatsu
提出日時 2022-05-07 20:31:42
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 104 ms / 2,000 ms
コード長 582 bytes
コンパイル時間 2,417 ms
コンパイル使用メモリ 200,200 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-04 17:05:01
合計ジャッジ時間 4,749 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 80 ms
4,380 KB
testcase_05 AC 76 ms
4,380 KB
testcase_06 AC 74 ms
4,376 KB
testcase_07 AC 67 ms
4,380 KB
testcase_08 AC 8 ms
4,380 KB
testcase_09 AC 81 ms
4,380 KB
testcase_10 AC 61 ms
4,376 KB
testcase_11 AC 70 ms
4,380 KB
testcase_12 AC 33 ms
4,376 KB
testcase_13 AC 39 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 72 ms
4,380 KB
testcase_17 AC 54 ms
4,376 KB
testcase_18 AC 58 ms
4,380 KB
testcase_19 AC 63 ms
4,376 KB
testcase_20 AC 89 ms
4,376 KB
testcase_21 AC 65 ms
4,380 KB
testcase_22 AC 28 ms
4,380 KB
testcase_23 AC 94 ms
4,376 KB
testcase_24 AC 103 ms
4,380 KB
testcase_25 AC 103 ms
4,380 KB
testcase_26 AC 104 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main() {
    long N;
    readf("%d\n", N);

    auto S = readln.chomp;

    long M = 998_244_353;

    long cntAB = S.count!(s => (s == 'A' || s == 'B'));

    long res = 1;
    foreach (i; 0 .. cntAB) {
        res = (res * (N - i)) % M;
        res = (res * powMod(i+1, M-2, M)) % M;
    }

    res.writeln;
}

long powMod(long x, long y, long z) {
    long res = 1;
    while (y > 0) {
        if (y % 2 == 1) {
            res *= x;
            if (res > z) res %= z;
        }
        x *= x;
        if (x > z) x %= z;
        y /= 2;
    }
    return res;
}
0