結果

問題 No.2031 Colored Brackets
ユーザー ShirotsumeShirotsume
提出日時 2022-07-03 01:08:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 6,254 ms
コンパイル使用メモリ 229,624 KB
実行使用メモリ 38,528 KB
最終ジャッジ日時 2023-10-13 20:57:04
合計ジャッジ時間 7,471 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 12 ms
13,452 KB
testcase_05 AC 5 ms
7,744 KB
testcase_06 AC 7 ms
9,436 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 18 ms
21,016 KB
testcase_09 AC 24 ms
27,096 KB
testcase_10 AC 30 ms
34,560 KB
testcase_11 AC 23 ms
26,384 KB
testcase_12 AC 33 ms
37,124 KB
testcase_13 AC 16 ms
19,256 KB
testcase_14 AC 34 ms
38,456 KB
testcase_15 AC 33 ms
38,464 KB
testcase_16 AC 34 ms
38,480 KB
testcase_17 AC 47 ms
38,528 KB
testcase_18 AC 29 ms
38,452 KB
testcase_19 AC 25 ms
31,392 KB
testcase_20 AC 15 ms
20,864 KB
testcase_21 AC 16 ms
21,584 KB
testcase_22 AC 18 ms
23,748 KB
testcase_23 AC 27 ms
36,168 KB
testcase_24 AC 1 ms
4,352 KB
testcase_25 AC 1 ms
4,352 KB
testcase_26 AC 1 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,352 KB
testcase_30 AC 1 ms
4,352 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,352 KB
testcase_33 AC 2 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
using ll = long long;
#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void)
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    vector<vector<mint>> dp(n, vector<mint>(n));
    dp[0][0] = 1;
    rep(p, n){
        if(s[p] == '('){
            rep(i, cnt + 1){
                int j = cnt - i;
                dp[i+1][j]+=dp[i][j];
                dp[i][j+1]+=dp[i][j];
                dp[i][j] = 0;
            }
            cnt++;
        }
        else{
            rep(i, cnt + 1){
                int j = cnt - i;
                if(i > 0)
                    dp[i-1][j]+=dp[i][j];
                if (j > 0)
                    dp[i][j-1]+=dp[i][j];
                dp[i][j]=0;
            }
            cnt--;
        }
    }
    cout << dp[0][0].val() << endl;
    return 0;
}
0