結果

問題 No.2031 Colored Brackets
ユーザー momoyuumomoyuu
提出日時 2022-08-18 09:32:08
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,316 bytes
コンパイル時間 4,272 ms
コンパイル使用メモリ 280,932 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-04-15 18:34:46
合計ジャッジ時間 5,438 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 19 ms
24,064 KB
testcase_05 AC 8 ms
11,520 KB
testcase_06 AC 12 ms
15,744 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 34 ms
39,168 KB
testcase_09 AC 42 ms
51,456 KB
testcase_10 AC 52 ms
65,920 KB
testcase_11 AC 40 ms
49,792 KB
testcase_12 AC 56 ms
71,552 KB
testcase_13 AC 28 ms
35,584 KB
testcase_14 AC 60 ms
73,728 KB
testcase_15 AC 59 ms
73,856 KB
testcase_16 AC 60 ms
73,728 KB
testcase_17 AC 63 ms
73,728 KB
testcase_18 AC 57 ms
73,728 KB
testcase_19 AC 46 ms
59,904 KB
testcase_20 AC 29 ms
38,656 KB
testcase_21 AC 30 ms
40,448 KB
testcase_22 AC 34 ms
44,672 KB
testcase_23 AC 53 ms
69,248 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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