結果

問題 No.1927 AB-CD
ユーザー tentententen
提出日時 2023-04-19 13:18:29
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 2,156 bytes
コンパイル時間 3,157 ms
コンパイル使用メモリ 90,000 KB
実行使用メモリ 41,216 KB
最終ジャッジ日時 2024-04-22 14:05:32
合計ジャッジ時間 7,438 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
37,092 KB
testcase_01 AC 46 ms
36,972 KB
testcase_02 AC 47 ms
37,272 KB
testcase_03 AC 48 ms
36,696 KB
testcase_04 AC 121 ms
40,208 KB
testcase_05 AC 122 ms
41,216 KB
testcase_06 AC 120 ms
40,036 KB
testcase_07 AC 118 ms
39,948 KB
testcase_08 AC 53 ms
36,988 KB
testcase_09 AC 120 ms
40,184 KB
testcase_10 AC 111 ms
39,884 KB
testcase_11 AC 119 ms
39,932 KB
testcase_12 AC 88 ms
39,168 KB
testcase_13 AC 103 ms
39,372 KB
testcase_14 AC 51 ms
37,140 KB
testcase_15 AC 61 ms
37,716 KB
testcase_16 AC 132 ms
39,848 KB
testcase_17 AC 125 ms
39,656 KB
testcase_18 AC 126 ms
39,480 KB
testcase_19 AC 126 ms
39,928 KB
testcase_20 AC 142 ms
40,324 KB
testcase_21 AC 127 ms
40,044 KB
testcase_22 AC 96 ms
39,144 KB
testcase_23 AC 136 ms
40,712 KB
testcase_24 AC 128 ms
40,868 KB
testcase_25 AC 129 ms
40,756 KB
testcase_26 AC 124 ms
40,780 KB
testcase_27 AC 47 ms
36,780 KB
testcase_28 AC 47 ms
37,100 KB
testcase_29 AC 49 ms
36,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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[] counts = new int[4];
        for (char c : sc.next().toCharArray()) {
            counts[c - 'A']++;
        }
        int x = counts[0] + counts[1];
        System.out.println(fact(n) * pow(fact(x) * fact(n - x) % MOD, MOD - 2) % 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;
        }
    }
    
    static long fact(int x) {
        long ans = 1;
        for (int i = 2; i <= x; i++) {
            ans *= i;
            ans %= MOD;
        }
        return ans;
    }
    
}
class Utilities {
    static String arrayToLineString(Object[] arr) {
        return Arrays.stream(arr).map(x -> x.toString()).collect(Collectors.joining("\n"));
    }
    
    static String arrayToLineString(int[] arr) {
        return String.join("\n", Arrays.stream(arr).mapToObj(String::valueOf).toArray(String[]::new));
    }
}
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 int[] nextIntArray() throws Exception {
        return Stream.of(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
0