結果

問題 No.1927 AB-CD
ユーザー tentententen
提出日時 2023-02-24 10:33:53
言語 Java21
(openjdk 21)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 2,240 bytes
コンパイル時間 3,822 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 55,500 KB
最終ジャッジ日時 2023-10-09 21:07:06
合計ジャッジ時間 7,414 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
49,604 KB
testcase_01 AC 38 ms
49,580 KB
testcase_02 AC 37 ms
49,312 KB
testcase_03 AC 39 ms
49,332 KB
testcase_04 AC 113 ms
52,336 KB
testcase_05 AC 100 ms
52,612 KB
testcase_06 AC 112 ms
52,592 KB
testcase_07 AC 98 ms
52,412 KB
testcase_08 AC 49 ms
49,600 KB
testcase_09 AC 114 ms
52,436 KB
testcase_10 AC 103 ms
52,776 KB
testcase_11 AC 106 ms
52,872 KB
testcase_12 AC 75 ms
51,836 KB
testcase_13 AC 81 ms
52,424 KB
testcase_14 AC 45 ms
49,220 KB
testcase_15 AC 52 ms
49,972 KB
testcase_16 AC 99 ms
52,256 KB
testcase_17 AC 105 ms
52,596 KB
testcase_18 AC 103 ms
52,852 KB
testcase_19 AC 110 ms
52,784 KB
testcase_20 AC 112 ms
52,592 KB
testcase_21 AC 106 ms
52,500 KB
testcase_22 AC 67 ms
50,552 KB
testcase_23 AC 128 ms
54,640 KB
testcase_24 AC 126 ms
54,544 KB
testcase_25 AC 132 ms
55,500 KB
testcase_26 AC 123 ms
54,800 KB
testcase_27 AC 38 ms
49,388 KB
testcase_28 AC 38 ms
49,348 KB
testcase_29 AC 39 ms
49,264 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