結果

問題 No.2106 Wild Cacco
ユーザー ぷらぷら
提出日時 2022-10-21 21:52:39
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 1,520 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 200,692 KB
実行使用メモリ 142,692 KB
最終ジャッジ日時 2023-09-13 22:12:15
合計ジャッジ時間 7,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,500 KB
testcase_01 AC 2 ms
7,564 KB
testcase_02 AC 2 ms
7,544 KB
testcase_03 AC 2 ms
7,504 KB
testcase_04 AC 3 ms
7,524 KB
testcase_05 AC 3 ms
7,592 KB
testcase_06 AC 3 ms
7,696 KB
testcase_07 AC 3 ms
7,712 KB
testcase_08 AC 3 ms
7,808 KB
testcase_09 AC 4 ms
7,968 KB
testcase_10 AC 3 ms
7,740 KB
testcase_11 AC 91 ms
43,488 KB
testcase_12 AC 178 ms
101,524 KB
testcase_13 AC 228 ms
128,372 KB
testcase_14 AC 123 ms
61,136 KB
testcase_15 AC 134 ms
66,952 KB
testcase_16 AC 219 ms
121,040 KB
testcase_17 AC 159 ms
78,496 KB
testcase_18 AC 144 ms
70,964 KB
testcase_19 AC 157 ms
78,508 KB
testcase_20 AC 175 ms
93,884 KB
testcase_21 AC 182 ms
97,560 KB
testcase_22 AC 111 ms
47,704 KB
testcase_23 AC 68 ms
7,444 KB
testcase_24 AC 105 ms
41,600 KB
testcase_25 AC 121 ms
51,864 KB
testcase_26 AC 277 ms
142,692 KB
testcase_27 AC 261 ms
137,332 KB
testcase_28 AC 267 ms
138,356 KB
testcase_29 AC 2 ms
7,456 KB
testcase_30 AC 274 ms
142,588 KB
testcase_31 AC 84 ms
22,996 KB
testcase_32 AC 87 ms
23,176 KB
testcase_33 AC 275 ms
142,604 KB
testcase_34 AC 278 ms
142,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

void mpl(int &x,int y) {
    x += y;
    if(x >= mod) x -= mod;
}

int dp1[4040][4040],dp2[4040][4040],sum[4040][4040];

int main() {
    string s;
    cin >> s;
    dp1[0][0] = 1;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < s.size(); j++) {
            if(!dp1[i][j]) continue;
            if(s[i] == '(' || s[i] == '.') {
                mpl(dp1[i+1][j+1],dp1[i][j]);
            }
            if((s[i] == ')' || s[i] == '.') && j >= 1) {
                mpl(dp1[i+1][j-1],dp1[i][j]);
            }
            if(s[i] == '?' || s[i] == '.') {
                mpl(dp1[i+1][j+1],dp1[i][j]);
            }
        }
    }
    dp2[0][0] = 1;
    for(int i = 0; i < s.size(); i++) {
        for(int j = 0; j < s.size(); j++) {
            if(!dp2[i][j]) continue;
            int id = s.size()-i-1;
            if(s[id] == ')' || s[id] == '.') {
                mpl(dp2[i+1][j+1],dp2[i][j]);
            }
            if((s[id] == '(' || s[id] == '.') && j >= 1) {
                mpl(dp2[i+1][j-1],dp2[i][j]);
            }
            if(s[id] == '?' || s[id] == '.') {
                mpl(dp2[i+1][j+1],dp2[i][j]);
                mpl(sum[i+1][j+1],dp2[i][j]);
            }
        }
    }
    mpl(sum[0][0],1);
    int ans = 0;
    for(int i = 0; i <= s.size(); i++) {
        for(int j = 0; j <= s.size(); j++) {
            mpl(ans,1ll*dp1[i][j]*sum[s.size()-i][j]%mod);
        }
    }
    cout << ans << endl;
}
0