結果

問題 No.2031 Colored Brackets
ユーザー tentententen
提出日時 2023-06-30 13:29:50
言語 Java21
(openjdk 21)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 2,251 bytes
コンパイル時間 4,520 ms
コンパイル使用メモリ 86,532 KB
実行使用メモリ 53,748 KB
最終ジャッジ日時 2023-09-21 07:07:12
合計ジャッジ時間 8,754 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,444 KB
testcase_01 AC 43 ms
49,532 KB
testcase_02 AC 42 ms
49,464 KB
testcase_03 AC 43 ms
49,528 KB
testcase_04 AC 56 ms
50,692 KB
testcase_05 AC 51 ms
50,140 KB
testcase_06 AC 69 ms
52,216 KB
testcase_07 AC 43 ms
49,416 KB
testcase_08 AC 76 ms
53,748 KB
testcase_09 AC 74 ms
52,508 KB
testcase_10 AC 76 ms
52,380 KB
testcase_11 AC 80 ms
52,472 KB
testcase_12 AC 75 ms
52,568 KB
testcase_13 AC 73 ms
52,132 KB
testcase_14 AC 77 ms
52,292 KB
testcase_15 AC 88 ms
52,396 KB
testcase_16 AC 87 ms
52,344 KB
testcase_17 AC 94 ms
52,940 KB
testcase_18 AC 64 ms
52,196 KB
testcase_19 AC 57 ms
50,324 KB
testcase_20 AC 55 ms
50,212 KB
testcase_21 AC 56 ms
50,172 KB
testcase_22 AC 56 ms
50,160 KB
testcase_23 AC 62 ms
51,932 KB
testcase_24 AC 44 ms
49,440 KB
testcase_25 AC 43 ms
49,528 KB
testcase_26 AC 43 ms
49,592 KB
testcase_27 AC 43 ms
49,576 KB
testcase_28 AC 43 ms
49,712 KB
testcase_29 AC 43 ms
49,472 KB
testcase_30 AC 43 ms
49,504 KB
testcase_31 AC 45 ms
49,480 KB
testcase_32 AC 44 ms
49,420 KB
testcase_33 AC 45 ms
49,408 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();
        char[] inputs = sc.next().toCharArray();
        int size = n / 2;
        int[] dp = new int[size + 1];
        dp[0] = 1;
        int current = 0;
        for (int i = 1; i <= n; i++) {
            if (inputs[i - 1] == '(') {
                current++;
                for (int j = current; j >= 1; j--) {
                    dp[j] += dp[j - 1];
                    dp[j] %= MOD;
                }
            } else {
                current--;
                for (int j = 0; j <= current; j++) {
                    dp[j] += dp[j + 1];
                    dp[j] %= MOD;
                }
                for (int j = current + 1; j <= size; j++) {
                    dp[j] = 0;
                }
            }
        }
        System.out.println(dp[0]);
    }
}
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