結果

問題 No.2106 Wild Cacco
ユーザー SumitacchanSumitacchan
提出日時 2022-09-03 18:10:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 389 ms / 2,000 ms
コード長 1,426 bytes
コンパイル時間 3,590 ms
コンパイル使用メモリ 238,096 KB
実行使用メモリ 222,216 KB
最終ジャッジ日時 2023-08-28 22:00:39
合計ジャッジ時間 12,885 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 279 ms
170,880 KB
testcase_12 AC 312 ms
180,696 KB
testcase_13 AC 333 ms
190,516 KB
testcase_14 AC 330 ms
200,748 KB
testcase_15 AC 345 ms
211,424 KB
testcase_16 AC 378 ms
222,216 KB
testcase_17 AC 370 ms
222,120 KB
testcase_18 AC 367 ms
222,096 KB
testcase_19 AC 368 ms
222,096 KB
testcase_20 AC 372 ms
222,152 KB
testcase_21 AC 378 ms
222,092 KB
testcase_22 AC 362 ms
222,148 KB
testcase_23 AC 362 ms
222,144 KB
testcase_24 AC 347 ms
211,360 KB
testcase_25 AC 370 ms
222,200 KB
testcase_26 AC 389 ms
222,096 KB
testcase_27 AC 370 ms
210,072 KB
testcase_28 AC 373 ms
212,336 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 353 ms
222,100 KB
testcase_32 AC 348 ms
222,192 KB
testcase_33 AC 384 ms
222,100 KB
testcase_34 AC 382 ms
222,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/convolution>
#include <atcoder/modint>
using namespace std;
using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)

using mint = modint998244353;

int main(){
    string s; cin >> s;
    if(s.size() % 2 != 0){
        cout << 0 << endl;
        return 0;
    }

    int n = s.size() / 2;
    vector<vector<vector<mint>>> dp(n + 1, vector<vector<mint>>(n + 1, vector<mint>(2, 0)));
    dp[0][0][0] = 1;

    REP(i, n + 1) REP(j, i + 1){
        int pos = i + j;
        if(pos == 2 * n) continue;

        const char c = s[pos];
        REP(k, 2){
            // '('
            if((c == '(' || c == '.') && i + 1 <= n){
                dp[i + 1][j][k] += dp[i][j][k];
            }
            // ')'
            if((c == ')' || c == '.') && j + 1 <= i){
                dp[i][j + 1][k] += dp[i][j][k];
            }
            // '{'
            if((c == '?' || c == '.') && i + 1 <= n){
                if(k == 0) dp[i + 1][j][k] += dp[i][j][k];
            }
            // '}'
            if((c == '?' || c == '.') && j + 1 <= i){
                dp[i][j + 1][1] += dp[i][j][k];
            }
        }
    }
    mint ans = dp[n][n][0] + dp[n][n][1];
    cout << ans.val() << endl;

    return 0;
}
0