結果

問題 No.2031 Colored Brackets
ユーザー dyktr_06dyktr_06
提出日時 2022-08-05 23:42:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,091 bytes
コンパイル時間 3,897 ms
コンパイル使用メモリ 232,140 KB
実行使用メモリ 814,516 KB
最終ジャッジ日時 2023-10-14 01:49:10
合計ジャッジ時間 6,580 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())
#define out(a) cout << a << "\n"

typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef pair<long long, long long> P;

const long long INF = 0x1fffffffffffffff;
const long long MOD = 998244353;
const double PI = acos(-1);
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }

ll n;
string s;

void input(){
    cin >> n >> s;
}
 
void solve(){
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(1 + n / 2, vector<ll>(n / 2 + 1)));
    ll l = 0, r = 0, currdiff = 0, prevdiff = 0;
    dp[0][0][0] = 1;
    rep(i, n){
        if(s[i] == '('){
            l++;
        }else{
            r++;
        }
        currdiff = l - r;
        for(int j = 0; j <= n / 2; j++){
            ll jj = j;
            if(s[i] == '('){
                jj++;
            }else{
                jj--;
            }
            if(jj < 0) continue;
            ll k1 = currdiff - jj, k2 = prevdiff - j;
            if(k1 < 0 || k2 < 0) continue;
            dp[i+1][jj][k1] += dp[i][j][k2];
            dp[i+1][k1][jj] += dp[i][k2][j];
            dp[i+1][jj][k1] %= MOD; 
            dp[i+1][k1][jj] %= MOD; 
        }
        prevdiff = currdiff;
    }
    out(dp[n][0][0]);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}
0