結果

問題 No.1677 mæx
ユーザー merom686merom686
提出日時 2021-09-10 22:53:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,462 bytes
コンパイル時間 2,083 ms
コンパイル使用メモリ 207,456 KB
実行使用メモリ 7,728 KB
最終ジャッジ日時 2023-09-02 20:18:20
合計ジャッジ時間 3,297 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 6 ms
6,664 KB
testcase_05 AC 6 ms
6,672 KB
testcase_06 AC 6 ms
6,612 KB
testcase_07 AC 6 ms
6,612 KB
testcase_08 AC 6 ms
6,612 KB
testcase_09 AC 6 ms
6,632 KB
testcase_10 AC 6 ms
6,632 KB
testcase_11 AC 6 ms
6,644 KB
testcase_12 AC 6 ms
6,624 KB
testcase_13 AC 6 ms
6,600 KB
testcase_14 AC 6 ms
6,624 KB
testcase_15 AC 6 ms
6,600 KB
testcase_16 AC 6 ms
6,640 KB
testcase_17 AC 7 ms
6,620 KB
testcase_18 AC 6 ms
6,624 KB
testcase_19 AC 1 ms
4,372 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 7 ms
7,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
using namespace std;
using ll = long long;

string s;
vector<int> a;

array<mint, 3> dfs(int i0) {
    array<mint, 3> r = {};
    if (s[i0] == 'm') {
        int i2;
        if (s[i0 + 4] == 'm') {
            i2 = a[i0 + 7] + 1;
        } else {
            i2 = i0 + 5;
        }
        array<mint, 3> x = dfs(i0 + 4);
        array<mint, 3> y = dfs(i2 + 1);
        if (s[i0 + 1] != 'e') {
            r[0] = x[0] * y[0];
            r[1] = (x[0] + x[1]) * (y[0] + y[1]) - r[0];
            r[2] = (x[0] + x[1] + x[2]) * (y[0] + y[1] + y[2]) - r[1] - r[0];
        }
        if (s[i0 + 1] != 'a') {
            r[0] += (x[1] + x[2]) * (y[1] + y[2]);
            r[1] += x[0] * y[0] + x[2] * y[0] + x[0] * y[2];
            r[2] += x[0] * y[1] + x[1] * y[0];
        }
    } else {
        if (s[i0] == '?') {
            r[0] = r[1] = r[2] = 1;
        } else {
            r[s[i0] - '0'] = 1;
        }
    }
    //cout << i0 << ' ' << r[0].val() << ' ' << r[1].val() << ' ' << r[2].val() << endl;
    return r;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    cin >> s >> k;
    int n = s.size();

    a.resize(n);
    stack<int> st;

    for (int i = 0; i < n; i++) {
        if (s[i] == '(') st.push(i);
        if (s[i] == ')') a[st.top()] = i, st.pop();
    }

    auto x = dfs(0);
    cout << x[k].val() << endl;

    return 0;
}
0