結果

問題 No.1677 mæx
ユーザー tktk_snsntktk_snsn
提出日時 2021-09-10 22:39:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,199 bytes
コンパイル時間 319 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 17,788 KB
最終ジャッジ日時 2023-09-02 19:26:49
合計ジャッジ時間 4,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from collections import defaultdict
import bisect
mod = 998244353
S = input()
N = len(S)
K = int(input())

sep = defaultdict(list)
brac = [0] * N
for i in range(1, N):
    if S[i] == "(":
        brac[i] = brac[i-1] + 1
    elif S[i] == ")":
        brac[i] = brac[i-1] - 1
    else:
        brac[i] = brac[i-1]
    if S[i] == ",":
        sep[brac[i]].append(i)
for k, v in sep.items():
    print(k, v)


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
    oper = []
    if S[L] == "?" or S[L] == "a":
        oper.append(max)
    if S[L] == "?" or S[L] == "e":
        oper.append(mex)
    L += 3

    dep = brac[L]
    p = bisect.bisect_left(sep[dep], L)
    M = sep[dep][p]
    A = rec(L, M)
    B = rec(M+1, R)
    res = [0, 0, 0]
    for op in oper:
        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