結果

問題 No.2031 Colored Brackets
ユーザー ぷらぷら
提出日時 2022-08-05 21:49:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 789 bytes
コンパイル時間 2,019 ms
コンパイル使用メモリ 199,884 KB
実行使用メモリ 24,156 KB
最終ジャッジ日時 2023-10-13 22:31:59
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 11 ms
11,128 KB
testcase_05 AC 7 ms
7,844 KB
testcase_06 AC 9 ms
9,340 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 16 ms
14,020 KB
testcase_09 AC 19 ms
16,152 KB
testcase_10 AC 22 ms
18,656 KB
testcase_11 AC 19 ms
16,032 KB
testcase_12 AC 23 ms
19,384 KB
testcase_13 AC 15 ms
13,732 KB
testcase_14 AC 24 ms
19,676 KB
testcase_15 AC 24 ms
19,800 KB
testcase_16 AC 24 ms
19,788 KB
testcase_17 AC 34 ms
24,156 KB
testcase_18 AC 14 ms
15,392 KB
testcase_19 AC 13 ms
14,084 KB
testcase_20 AC 10 ms
11,936 KB
testcase_21 AC 10 ms
12,096 KB
testcase_22 AC 11 ms
12,516 KB
testcase_23 AC 13 ms
14,948 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 1 ms
4,356 KB
testcase_26 AC 2 ms
4,352 KB
testcase_27 AC 2 ms
4,352 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 3 ms
4,532 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 3 ms
4,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

int dp[3030][3030];

int main() {
    int N;
    string S;
    cin >> N >> S;
    int sum = 0;
    dp[0][0] = 1;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j <= sum; j++) {
            if(S[i] == '(') {
                dp[i+1][j+1] += dp[i][j];
                if(dp[i+1][j+1] >= mod) dp[i+1][j+1] -= mod;
            }
            else if(j) {
                dp[i+1][j-1] += dp[i][j];
                if(dp[i+1][j-1] >= mod) dp[i+1][j-1] -= mod;
            }
            dp[i+1][j] += dp[i][j];
            if(dp[i+1][j] >= mod) dp[i+1][j] -= mod;
        }
        if(S[i] == '(') {
            sum++;
        }
        else {
            sum--;
        }
    }
    cout << dp[N][0] << endl;
}
0