結果

問題 No.2031 Colored Brackets
ユーザー dyktr_06dyktr_06
提出日時 2022-08-05 23:50:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,281 bytes
コンパイル時間 3,901 ms
コンパイル使用メモリ 236,200 KB
実行使用メモリ 31,692 KB
最終ジャッジ日時 2023-10-14 01:58:04
合計ジャッジ時間 11,945 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,700 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 819 ms
13,752 KB
testcase_05 AC 186 ms
7,316 KB
testcase_06 AC 363 ms
9,424 KB
testcase_07 AC 2 ms
4,356 KB
testcase_08 TLE -
testcase_09 TLE -
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<ll>> dp(n / 2 + 1, vector<ll>(n / 2 + 1));
    vector<vector<ll>> tmp(n / 2 + 1, vector<ll>(n / 2 + 1));
    ll l = 0, r = 0, currdiff = 0, prevdiff = 0;
    dp[0][0] = 1;
    rep(i, n){
        if(s[i] == '('){
            l++;
        }else{
            r++;
        }
        currdiff = l - r;
        vector<P> p;
        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;
            tmp[jj][k1] += dp[j][k2];
            tmp[jj][k1] %= MOD; 
            tmp[k1][jj] += dp[k2][j];
            tmp[k1][jj] %= MOD; 
            p.push_back({jj, k1});
        }
        prevdiff = currdiff;
        dp = tmp;
        for(auto x : p){
            tmp[x.first][x.second] = 0;
            tmp[x.second][x.first] = 0;
        }
    }
    out(dp[0][0]);
}

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