結果

問題 No.2031 Colored Brackets
ユーザー momoyuumomoyuu
提出日時 2022-08-18 09:32:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 2,816 ms
コンパイル使用メモリ 250,964 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-10-05 20:35:12
合計ジャッジ時間 4,782 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template<class t> using vc = vector<t>;
template<class t> using vvc = vc<vc<t>>;
using pi = pair<int,int>;
using vi = vc<int>;
using vvi = vvc<int>;

#define rep(i,a,b) for (int i = a; i < b; i++)
#define irep(i,a,b) for (int i = a; i > b; i--)
#define print(n) cout << n << endl
#define rup(a,b) (a+b-1)/b


int main(){
    cout << fixed << setprecision(15);
    
    int N;
    string S;
    cin>>N>>S;
    ll mod = 998244353;
    vvc<ll> dp(N,vc<ll>(N,0));
    int now = 1;
    dp[0][1] ++;
    dp[0][0] ++;
    rep(i,0,N-1){
        if (S[i+1]=='('){
            rep(j,0,now+1){
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= mod;
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= mod;
            }
            now ++;
        }else{
            rep(j,0,now+1){
                if (j!=0){
                    dp[i+1][j-1] += dp[i][j];
                    dp[i+1][j-1] %= mod;
                }
                if(j!=now){
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= mod;
                }
            }
            now --;
        }
    }
    print(dp[N-1][0]);
    
    //system("pause");
    return 0;
}
0