結果

問題 No.1677 mæx
ユーザー tktk_snsntktk_snsn
提出日時 2021-09-10 22:28:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,086 bytes
コンパイル時間 863 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 13,108 KB
最終ジャッジ日時 2023-09-02 18:43:25
合計ジャッジ時間 4,013 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,636 KB
testcase_01 AC 16 ms
8,172 KB
testcase_02 AC 16 ms
8,152 KB
testcase_03 AC 15 ms
8,264 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 #

mod = 998244353
S = input()
N = len(S)
K = int(input())

if N == 1:
    if S == "?" or S == str(K):
        print(1)
    else:
        print(0)
    exit()


def mex(a, b):
    for i in range(3):
        if not i in [a, b]:
            return i


def rec(L, R):
    if L + 1 >= R:
        if S[L] == "?":
            return [1, 1, 1]
        res = [0, 0, 0]
        res[int(S[L])] += 1
        return res

    R -= 1
    L += 1
    operand = []
    if S[L] == "?" or S[L] == "a":
        operand.append(max)
    if S[L] == "?" or S[L] == "e":
        operand.append(mex)
    L += 3

    br = 0
    for i in range(L, R):
        if S[i] == "(":
            br += 1
        elif S[i] == ")":
            br -= 1
        elif S[i] == "," and br == 0:
            M = i
            break

    A = rec(L, M)
    B = rec(M+1, R)
    res = [0, 0, 0]
    for op in operand:
        for i, a in enumerate(A):
            for j, b in enumerate(B):
                idx = op(i, j)
                res[idx] += a * b % mod
                res[idx] %= mod
    return res


ans = rec(0, N)[K]
print(ans)
0