結果

問題 No.1927 AB-CD
ユーザー tentententen
提出日時 2022-09-27 11:42:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 1,711 bytes
コンパイル時間 2,136 ms
コンパイル使用メモリ 73,880 KB
実行使用メモリ 55,048 KB
最終ジャッジ日時 2023-08-24 03:44:07
合計ジャッジ時間 7,299 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,324 KB
testcase_01 AC 44 ms
49,356 KB
testcase_02 AC 44 ms
49,240 KB
testcase_03 AC 46 ms
49,252 KB
testcase_04 AC 116 ms
52,432 KB
testcase_05 AC 126 ms
52,228 KB
testcase_06 AC 122 ms
52,208 KB
testcase_07 AC 121 ms
52,252 KB
testcase_08 AC 55 ms
50,564 KB
testcase_09 AC 129 ms
52,348 KB
testcase_10 AC 118 ms
52,352 KB
testcase_11 AC 126 ms
52,192 KB
testcase_12 AC 88 ms
52,136 KB
testcase_13 AC 92 ms
51,560 KB
testcase_14 AC 51 ms
49,248 KB
testcase_15 AC 60 ms
49,644 KB
testcase_16 AC 124 ms
52,480 KB
testcase_17 AC 115 ms
52,344 KB
testcase_18 AC 107 ms
52,796 KB
testcase_19 AC 119 ms
52,412 KB
testcase_20 AC 130 ms
52,384 KB
testcase_21 AC 118 ms
52,492 KB
testcase_22 AC 76 ms
50,556 KB
testcase_23 AC 138 ms
54,140 KB
testcase_24 AC 146 ms
54,012 KB
testcase_25 AC 136 ms
54,560 KB
testcase_26 AC 140 ms
55,048 KB
testcase_27 AC 46 ms
49,260 KB
testcase_28 AC 45 ms
49,340 KB
testcase_29 AC 45 ms
49,368 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;
        int cd = 0;
        for (char c : sc.next().toCharArray()) {
            if (c == 'A' || c == 'B') {
                ab++;
            } else {
                cd++;
            }
        }
        System.out.println(fact(n) * pow(fact(ab), MOD - 2) % MOD * pow(fact(cd), MOD - 2) %  MOD);
    }
    
    static long fact(int x) {
        long ans = 1;
        for (int i = 1; i <= x; i++) {
            ans *= i;
            ans %= MOD;
        }
        return ans;
    }
    
    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("");
    StringBuilder sb = new StringBuilder();
    
    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