結果

問題 No.2031 Colored Brackets
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-13 05:14:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 2,000 ms
コード長 1,335 bytes
コンパイル時間 1,272 ms
コンパイル使用メモリ 111,968 KB
実行使用メモリ 73,600 KB
最終ジャッジ日時 2023-08-19 09:18:15
合計ジャッジ時間 3,535 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 19 ms
23,628 KB
testcase_05 AC 8 ms
11,216 KB
testcase_06 AC 12 ms
15,560 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 31 ms
38,944 KB
testcase_09 AC 42 ms
51,136 KB
testcase_10 AC 54 ms
65,672 KB
testcase_11 AC 39 ms
49,504 KB
testcase_12 AC 58 ms
71,200 KB
testcase_13 AC 28 ms
35,248 KB
testcase_14 AC 59 ms
73,600 KB
testcase_15 AC 59 ms
73,592 KB
testcase_16 AC 59 ms
73,504 KB
testcase_17 AC 80 ms
73,532 KB
testcase_18 AC 53 ms
73,548 KB
testcase_19 AC 42 ms
59,512 KB
testcase_20 AC 28 ms
38,656 KB
testcase_21 AC 29 ms
40,268 KB
testcase_22 AC 32 ms
44,204 KB
testcase_23 AC 49 ms
69,080 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

const ll modc = 998244353;

int main(){

    ll N, cnt=0, k;
    string S;
    cin >> N >> S;

    vector<vector<ll>> dp(N, vector<ll>(N));
    dp[0][0] = 1;

    for (int i=0; i<N; i++){
        if (S[i] == '('){
            for (int j=0; j<=cnt; j++){
                k = cnt-j;
                if (j+1<N){
                    dp[j+1][k] += dp[j][k];
                    dp[j+1][k] %= modc;
                }
                if (k+1<N){
                    dp[j][k+1] += dp[j][k];
                    dp[j][k+1] %= modc;
                }
                dp[j][k] = 0;
            }
            cnt++;
        }
        else{
            for (int j=0; j<=cnt; j++){
                k = cnt-j;
                if (j){
                    dp[j-1][k] += dp[j][k];
                    dp[j-1][k] %= modc;
                }
                if (k){
                    dp[j][k-1] += dp[j][k];
                    dp[j][k-1] %= modc;
                }
                dp[j][k] = 0;
            }
            cnt--;
        }
    }

    cout << dp[0][0] << endl;

    return 0;
}
0