結果

問題 No.2031 Colored Brackets
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-13 05:06:47
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,098 bytes
コンパイル時間 981 ms
コンパイル使用メモリ 110,488 KB
最終ジャッジ日時 2025-02-12 23:51:23
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 11 TLE * 19
権限があれば一括ダウンロードができます

ソースコード

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++){
        vector<vector<ll>> pd(N, vector<ll>(N));
        if (S[i] == '('){
            cnt++;
            for (int j=0; j<=cnt; j++){
                k = cnt-j;
                if (j) pd[j][k] += dp[j-1][k];
                if (k) pd[j][k] += dp[j][k-1];
                pd[j][k] %= modc;
            }
        }
        else{
            cnt--;
            for (int j=0; j<=cnt; j++){
                k = cnt-j;
                if (j+1<N) pd[j][k] += dp[j+1][k];
                if (k+1<N) pd[j][k] += dp[j][k+1];
                pd[j][k] %= modc;
            }
        }
        swap(dp, pd);
    }

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

    return 0;
}
0