結果

問題 No.1677 mæx
ユーザー みここみここ
提出日時 2021-09-10 22:23:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,397 bytes
コンパイル時間 1,309 ms
コンパイル使用メモリ 71,632 KB
実行使用メモリ 76,000 KB
最終ジャッジ日時 2023-09-02 18:32:11
合計ジャッジ時間 5,596 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

const ll MOD = 998244353;

int mex(int a, int b){
    if(a > b) swap(a, b);
    if(a > 0) return 0;
    if(b == 1) return 2;
    return 1;
}

vector<ll> rec(int l, int r, string &s){
    vector<ll> res(3);
    if(r - l == 1){
        if(s[l] == '?'){
            for(int k = 0; k < 3; k++) res[k]++;
        }
        else res[s[l] - '0']++;
    }
    else{
        int h = 0;
        vector<ll> p, q;
        for(int i = l + 4; i < r; i++){
            if(s[i] == '(') h++;
            if(s[i] == ')') h--;
            if(s[i] == ',' && h == 0){
                p = rec(l + 4, i, s), q = rec(i + 1, r - 1, s);
                break;
            }
        }
        if(s[1] != 'a'){
            for(int a = 0; a < 3; a++){
                for(int b = 0; b < 3; b++){
                    int c = mex(a, b);
                    res[c] = (res[c] + p[a] * q[b]) % MOD;
                }
            }
        }
        if(s[1] != 'e'){
            for(int a = 0; a < 3; a++){
                for(int b = 0; b < 3; b++){
                    int c = max(a, b);
                    res[c] = (res[c] + p[a] * q[b]) % MOD;
                }
            }
        }
    }
    return res;
}

int main()
{
    string s;
    int k;
    cin >> s >> k;
    vector<ll> ans = rec(0, (int)s.size(), s);
    cout << ans[k] << endl;
}
0