結果

問題 No.1927 AB-CD
ユーザー shojin_proshojin_pro
提出日時 2022-05-06 22:17:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 9,898 bytes
コンパイル時間 2,630 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 49,324 KB
最終ジャッジ日時 2024-07-05 23:32:28
合計ジャッジ時間 7,243 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
44,328 KB
testcase_01 AC 85 ms
44,264 KB
testcase_02 AC 79 ms
44,180 KB
testcase_03 AC 86 ms
44,396 KB
testcase_04 AC 134 ms
49,100 KB
testcase_05 AC 139 ms
49,324 KB
testcase_06 AC 138 ms
49,088 KB
testcase_07 AC 127 ms
49,024 KB
testcase_08 AC 97 ms
44,384 KB
testcase_09 AC 139 ms
49,056 KB
testcase_10 AC 128 ms
49,128 KB
testcase_11 AC 138 ms
49,160 KB
testcase_12 AC 102 ms
45,304 KB
testcase_13 AC 119 ms
45,596 KB
testcase_14 AC 95 ms
44,540 KB
testcase_15 AC 98 ms
44,532 KB
testcase_16 AC 138 ms
49,184 KB
testcase_17 AC 131 ms
48,928 KB
testcase_18 AC 137 ms
48,976 KB
testcase_19 AC 133 ms
49,080 KB
testcase_20 AC 142 ms
49,104 KB
testcase_21 AC 134 ms
49,192 KB
testcase_22 AC 105 ms
44,888 KB
testcase_23 AC 142 ms
49,056 KB
testcase_24 AC 131 ms
49,192 KB
testcase_25 AC 132 ms
49,232 KB
testcase_26 AC 139 ms
49,232 KB
testcase_27 AC 83 ms
44,544 KB
testcase_28 AC 82 ms
44,384 KB
testcase_29 AC 83 ms
44,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    static ContestScanner sc = new ContestScanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static StringBuilder sb = new StringBuilder();
    static long mod = 998244353;
    static Combination comb = new Combination(400000);
    public static void main(String[] args) throws Exception {
        //int T = sc.nextInt();
        //for(int i = 0; i < T; i++)solve();
        
        solve();
        pw.flush();
    }

    public static void solve() {
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int cnt = 0;
        for(char c : s){
            if(c-'A' <= 1){
                cnt++;
            }
        }
        pw.println(comb.comb(n,cnt));
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

        public static void save_sort(long[] array) {
            shuffle(array);
            Arrays.sort(array);
        }

        public static long[] shuffle(long[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                long randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }

    }
}

class Combination {
        final static long mod = 998244353;
        private static long[] fact, ifact;
    
        public Combination(int n) {
            fact = new long[n + 1];
            ifact = new long[n + 1];
            fact[0] = 1;
            long ln = n;
            for (long i = 1; i <= ln; ++i) {
                int ii = (int) i;
                fact[ii] = fact[ii - 1] % mod * i % mod;
            }
            ifact[n] = pow(fact[n], this.mod - 2);
            for (int i = n; i >= 1; --i) {
                int ii = (int) i;
                ifact[ii - 1] = ifact[ii] % mod * i % mod;
            }
        }
    
        public static long comb(int n, int k) {
            if (k < 0 || k > n)
                return 0;
            return fact[n] % mod * ifact[k] % mod * ifact[n - k] % mod;
        }
    
        public static long perm(int n, int k) {
            return comb(n, k) * fact[k] % mod;
        }
    
        public static long pow(long a, long b) {
            long ret = 1;
            long tmp = a;
            while (b > 0) {
                if ((b & 1) == 1) {
                    ret = (ret * tmp) % mod;
                }
                tmp = (tmp * tmp) % mod;
                b = b >> 1;
            }
            return ret;
        }
    }

/**
 * refercence : https://github.com/NASU41/AtCoderLibraryForJava/blob/master/ContestIO/ContestScanner.java
 */
class ContestScanner {
    private final java.io.InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private static final long LONG_MAX_TENTHS = 922337203685477580L;
    private static final int LONG_MAX_LAST_DIGIT = 7;
    private static final int LONG_MIN_LAST_DIGIT = 8;

    public ContestScanner(java.io.InputStream in){
        this.in = in;
    }
    public ContestScanner(java.io.File file) throws java.io.FileNotFoundException {
        this(new java.io.BufferedInputStream(new java.io.FileInputStream(file)));
    }
    public ContestScanner(){
        this(System.in);
    }
 
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (java.io.IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { 
        if (hasNextByte()) return buffer[ptr++]; else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new java.util.NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext()) throw new java.util.NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                int digit = b - '0';
                if (n >= LONG_MAX_TENTHS) {
                    if (n == LONG_MAX_TENTHS) {
                        if (minus) {
                            if (digit <= LONG_MIN_LAST_DIGIT) {
                                n = -n * 10 - digit;
                                b = readByte();
                                if (!isPrintableChar(b)) {
                                    return n;
                                } else if (b < '0' || '9' < b) {
                                    throw new NumberFormatException(
                                        String.format("%d%s... is not number", n, Character.toString(b))
                                    );
                                }
                            }
                        } else {
                            if (digit <= LONG_MAX_LAST_DIGIT) {
                                n = n * 10 + digit;
                                b = readByte();
                                if (!isPrintableChar(b)) {
                                    return n;
                                } else if (b < '0' || '9' < b) {
                                    throw new NumberFormatException(
                                        String.format("%d%s... is not number", n, Character.toString(b))
                                    );
                                }
                            }
                        }
                    }
                    throw new ArithmeticException(
                        String.format("%s%d%d... overflows long.", minus ? "-" : "", n, digit)
                    );
                }
                n = n * 10 + digit;
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
 
    public long[] nextLongArray(int length){
        long[] array = new long[length];
        for(int i=0; i<length; i++) array[i] = this.nextLong();
        return array;
    }
    public long[] nextLongArray(int length, java.util.function.LongUnaryOperator map){
        long[] array = new long[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsLong(this.nextLong());
        return array;
    }
    public int[] nextIntArray(int length){
        int[] array = new int[length];
        for(int i=0; i<length; i++) array[i] = this.nextInt();
        return array;
    }
    public int[] nextIntArray(int length, java.util.function.IntUnaryOperator map){
        int[] array = new int[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsInt(this.nextInt());
        return array;
    }
    public double[] nextDoubleArray(int length){
        double[] array = new double[length];
        for(int i=0; i<length; i++) array[i] = this.nextDouble();
        return array;
    }
    public double[] nextDoubleArray(int length, java.util.function.DoubleUnaryOperator map){
        double[] array = new double[length];
        for(int i=0; i<length; i++) array[i] = map.applyAsDouble(this.nextDouble());
        return array;
    }
 
    public long[][] nextLongMatrix(int height, int width){
        long[][] mat = new long[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextLong();
        }
        return mat;
    }
    public int[][] nextIntMatrix(int height, int width){
        int[][] mat = new int[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextInt();
        }
        return mat;
    }
    public double[][] nextDoubleMatrix(int height, int width){
        double[][] mat = new double[height][width];
        for(int h=0; h<height; h++) for(int w=0; w<width; w++){
            mat[h][w] = this.nextDouble();
        }
        return mat;
    }
 
    public char[][] nextCharMatrix(int height, int width){
        char[][] mat = new char[height][width];
        for(int h=0; h<height; h++){
            String s = this.next();
            for(int w=0; w<width; w++){
                mat[h][w] = s.charAt(w);
            }
        }
        return mat;
    }
}
0