結果

問題 No.1927 AB-CD
ユーザー tentententen
提出日時 2023-08-08 12:50:17
言語 Java21
(openjdk 21)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,242 bytes
コンパイル時間 2,781 ms
コンパイル使用メモリ 91,120 KB
実行使用メモリ 41,604 KB
最終ジャッジ日時 2024-04-26 05:43:24
合計ジャッジ時間 6,836 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
37,412 KB
testcase_01 AC 51 ms
36,840 KB
testcase_02 AC 52 ms
37,152 KB
testcase_03 AC 52 ms
37,200 KB
testcase_04 AC 131 ms
40,304 KB
testcase_05 AC 129 ms
40,068 KB
testcase_06 AC 128 ms
39,924 KB
testcase_07 AC 123 ms
40,168 KB
testcase_08 AC 60 ms
37,444 KB
testcase_09 AC 123 ms
40,168 KB
testcase_10 AC 121 ms
39,956 KB
testcase_11 AC 128 ms
40,324 KB
testcase_12 AC 98 ms
39,568 KB
testcase_13 AC 100 ms
39,544 KB
testcase_14 AC 56 ms
36,948 KB
testcase_15 AC 70 ms
38,084 KB
testcase_16 AC 132 ms
40,012 KB
testcase_17 AC 119 ms
39,772 KB
testcase_18 AC 118 ms
39,788 KB
testcase_19 AC 122 ms
40,776 KB
testcase_20 AC 136 ms
41,604 KB
testcase_21 AC 123 ms
39,984 KB
testcase_22 AC 90 ms
39,136 KB
testcase_23 AC 140 ms
40,728 KB
testcase_24 AC 139 ms
41,092 KB
testcase_25 AC 145 ms
40,492 KB
testcase_26 AC 144 ms
40,964 KB
testcase_27 AC 52 ms
37,256 KB
testcase_28 AC 53 ms
37,308 KB
testcase_29 AC 52 ms
36,812 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 ab = 0;
        int cd = 0;
        for (char c : sc.next().toCharArray()) {
            if (c == 'A' || c == 'B') {
                ab++;
            } else {
                cd++;
            }
        }
        long ans = fact(n) * pow(fact(ab), MOD - 2) % MOD * pow(fact(cd), MOD - 2) % MOD;
        System.out.println(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;
        }
    }
    
    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