結果

問題 No.2106 Wild Cacco
ユーザー 👑 hitonanodehitonanode
提出日時 2022-09-19 22:41:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 155 ms / 2,000 ms
コード長 1,689 bytes
コンパイル時間 7,143 ms
コンパイル使用メモリ 245,892 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 22:00:49
合計ジャッジ時間 10,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 34 ms
4,384 KB
testcase_12 AC 76 ms
4,380 KB
testcase_13 AC 107 ms
4,380 KB
testcase_14 AC 44 ms
4,380 KB
testcase_15 AC 45 ms
4,380 KB
testcase_16 AC 96 ms
4,384 KB
testcase_17 AC 85 ms
4,380 KB
testcase_18 AC 61 ms
4,384 KB
testcase_19 AC 71 ms
4,384 KB
testcase_20 AC 65 ms
4,380 KB
testcase_21 AC 74 ms
4,384 KB
testcase_22 AC 39 ms
4,380 KB
testcase_23 AC 45 ms
4,384 KB
testcase_24 AC 55 ms
4,384 KB
testcase_25 AC 63 ms
4,380 KB
testcase_26 AC 154 ms
4,380 KB
testcase_27 AC 146 ms
4,380 KB
testcase_28 AC 147 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 154 ms
4,384 KB
testcase_31 AC 34 ms
4,380 KB
testcase_32 AC 58 ms
4,384 KB
testcase_33 AC 155 ms
4,380 KB
testcase_34 AC 154 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// Validator
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

#include "testlib.h"

#include <atcoder/modint>
using mint = atcoder::modint998244353;

#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define REP(i, n) FOR(i, 0, n)

int main(int argc, char *argv[]) {
    registerValidation(argc, argv);

    string S = inf.readString();
    cerr << S << ' ' << S.size() << endl;
    inf.readEof();

    assert(1 <= S.size() and S.size() <= 4000);
    for (char c : S) {
        assert(c == '(' or c == ')' or c == '?' or c == '.');
    }

    const int N = S.size();

    vector dp(2, vector<mint>(N + 1));
    dp[0][0] = dp[1][0] = 1;

    for (auto c : S) {
        vector dpnxt(2, vector<mint>(N + 1));

        if (c != ')' and c != '?') {
            // Insert (
            REP(b, 2) REP(i, dp[b].size()) {
                if (dp[b][i].val()) { dpnxt[b][i + 1] += dp[b][i]; }
            }
        }

        if (c != '(' and c != '?') {
            // Insert )
            REP(b, 2) REP(i, dp[b].size()) {
                if (dp[b][i].val() and i) { dpnxt[b][i - 1] += dp[b][i]; }
            }
        }

        if (c == '.' or c == '?') {
            // Insert ?
            REP(b, 2) REP(i, dp[b].size()) {
                if (dp[b][i].val()) {
                    if (b == 0) {
                        dpnxt[0][i + 1] += dp[b][i];
                        dpnxt[1][i + 1] += dp[b][i];
                    } else {
                        if (i) { dpnxt[1][i - 1] += dp[b][i]; }
                    }
                }
            }
        }
        dp = dpnxt;
    }
    cout << dp.at(1).at(0).val() << endl;
}
0