結果

問題 No.1927 AB-CD
ユーザー tentententen
提出日時 2022-08-09 18:14:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 1,654 bytes
コンパイル時間 4,330 ms
コンパイル使用メモリ 77,328 KB
実行使用メモリ 75,764 KB
最終ジャッジ日時 2023-10-20 03:10:10
合計ジャッジ時間 8,854 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
53,488 KB
testcase_01 AC 56 ms
53,548 KB
testcase_02 AC 55 ms
53,532 KB
testcase_03 AC 56 ms
52,412 KB
testcase_04 AC 154 ms
69,604 KB
testcase_05 AC 146 ms
69,312 KB
testcase_06 AC 149 ms
67,348 KB
testcase_07 AC 143 ms
67,268 KB
testcase_08 AC 68 ms
54,736 KB
testcase_09 AC 149 ms
69,520 KB
testcase_10 AC 127 ms
65,384 KB
testcase_11 AC 145 ms
67,472 KB
testcase_12 AC 97 ms
60,860 KB
testcase_13 AC 106 ms
63,180 KB
testcase_14 AC 65 ms
54,680 KB
testcase_15 AC 75 ms
57,716 KB
testcase_16 AC 131 ms
67,240 KB
testcase_17 AC 130 ms
65,352 KB
testcase_18 AC 133 ms
65,324 KB
testcase_19 AC 138 ms
67,480 KB
testcase_20 AC 153 ms
71,308 KB
testcase_21 AC 139 ms
67,420 KB
testcase_22 AC 98 ms
61,100 KB
testcase_23 AC 150 ms
73,624 KB
testcase_24 AC 152 ms
75,764 KB
testcase_25 AC 171 ms
75,660 KB
testcase_26 AC 153 ms
75,548 KB
testcase_27 AC 56 ms
53,540 KB
testcase_28 AC 56 ms
53,548 KB
testcase_29 AC 56 ms
53,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static final int MOD = 998244353;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int ab = 0;
        for (char c : sc.next().toCharArray()) {
            if (c == 'A' || c == 'B') {
                ab++;
            }
        }
        long ans = fact(n);
        ans *= pow(fact(n - ab), MOD - 2);
        ans %= MOD;
        ans *= pow(fact(ab), MOD - 2);
        ans %= MOD;
        System.out.println(ans);
    }
    
    static long fact(int x) {
        if (x == 0) {
            return 1;
        } else {
            return fact(x - 1) * x % MOD;
        }
    }
    
    static long pow(long x, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 0) {
            return pow(x * x % MOD, p / 2);
        } else {
            return pow(x, p - 1) * x % MOD;
        }
    }
}

class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0