結果

問題 No.1677 mæx
ユーザー KudeKude
提出日時 2021-09-10 22:18:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,905 bytes
コンパイル時間 4,157 ms
コンパイル使用メモリ 260,816 KB
実行使用メモリ 8,264 KB
最終ジャッジ日時 2023-09-02 18:19:06
合計ジャッジ時間 5,467 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 7 ms
7,116 KB
testcase_05 AC 8 ms
7,228 KB
testcase_06 AC 8 ms
7,112 KB
testcase_07 AC 8 ms
7,284 KB
testcase_08 AC 8 ms
7,300 KB
testcase_09 AC 7 ms
7,316 KB
testcase_10 AC 8 ms
7,196 KB
testcase_11 AC 7 ms
7,280 KB
testcase_12 AC 8 ms
7,124 KB
testcase_13 AC 8 ms
7,236 KB
testcase_14 AC 8 ms
7,284 KB
testcase_15 AC 8 ms
7,288 KB
testcase_16 AC 7 ms
7,284 KB
testcase_17 AC 8 ms
7,128 KB
testcase_18 AC 8 ms
7,304 KB
testcase_19 AC 1 ms
4,368 KB
testcase_20 AC 1 ms
4,372 KB
testcase_21 AC 8 ms
8,264 KB
権限があれば一括ダウンロードができます

ソースコード

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(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using mint = modint998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    const int n = s.size();
    VI rparen(n, -1);
    VI comm(n, -1);
    VI st;
    rep(i, n) {
        if (s[i] == '(') st.push_back(i);
        else if (s[i] == ')') {
            rparen[st.back()] = i;
            st.pop_back();
        } else if (s[i] == ',') {
            comm[st.back()] = i;
        }
    }
    auto mex = [&](int i, int j) {
        if (i > j) swap(i, j);
        if (i) return 0;
        if (j == 1) return 2;
        else return 1;
    };
    using T = array<mint, 3>;
    auto dfs = [&](auto&& self, int left, int right) {
        T res;
        if ('0' <= s[left] && s[left] <= '2') {
            res[s[left] - '0'] = 1;
            return res;
        }
        if (s[left] == '?') {
            rep(i, 3) res[i] = 1;
            return res;
        }
        int lp = left + 3;
        T r1 = self(self, lp + 1, comm[lp]);
        T r2 = self(self, comm[lp] + 1, rparen[lp]);
        if (s[left + 1] != 'e') {
            rep(i, 3) rep(j, 3) res[max(i, j)] += r1[i] * r2[j];
        }
        if (s[left + 1] != 'a') {
            rep(i, 3) rep(j, 3) res[mex(i, j)] += r1[i] * r2[j];
        }
        return res;
    };
    T res = dfs(dfs, 0, n);
    int k;
    cin >> k;
    cout << res[k].val() << endl;
}
0