結果

問題 No.1677 mæx
ユーザー mkawa2mkawa2
提出日時 2021-09-10 22:44:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 979 ms / 2,000 ms
コード長 1,559 bytes
コンパイル時間 73 ms
コンパイル使用メモリ 10,792 KB
実行使用メモリ 58,256 KB
最終ジャッジ日時 2023-09-02 19:47:31
合計ジャッジ時間 14,488 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,884 KB
testcase_01 AC 21 ms
8,860 KB
testcase_02 AC 21 ms
8,744 KB
testcase_03 AC 21 ms
8,744 KB
testcase_04 AC 740 ms
49,868 KB
testcase_05 AC 738 ms
49,764 KB
testcase_06 AC 733 ms
49,672 KB
testcase_07 AC 732 ms
49,700 KB
testcase_08 AC 739 ms
50,008 KB
testcase_09 AC 734 ms
50,024 KB
testcase_10 AC 749 ms
49,840 KB
testcase_11 AC 743 ms
49,936 KB
testcase_12 AC 738 ms
49,868 KB
testcase_13 AC 745 ms
49,700 KB
testcase_14 AC 972 ms
50,712 KB
testcase_15 AC 974 ms
50,652 KB
testcase_16 AC 972 ms
50,440 KB
testcase_17 AC 976 ms
50,648 KB
testcase_18 AC 978 ms
50,824 KB
testcase_19 AC 21 ms
8,820 KB
testcase_20 AC 20 ms
8,740 KB
testcase_21 AC 979 ms
58,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**20
md = 998244353
# md = 10**9+7

from functools import lru_cache
from collections import defaultdict

@lru_cache(None)
def mex(a,b):
    for i in range(3):
        if i!=a and i!=b:
            return i

@lru_cache(None)
def solve(l,r,k):
    # print(l,r,k,s[l:r])
    if r-l==1:
        return s[l]=="?" or int(s[l])==k
    m=mm[l]
    res=0
    if s[l+1]!="e":
        for a in range(3):
            for b in range(3):
                if max(a,b)!=k:continue
                res+=solve(l+4,m,a)*solve(m+1,r-1,b)%md
                res%=md
    if s[l+1]!="a":
        for a in range(3):
            for b in range(3):
                if mex(a,b)!=k:continue
                res+=solve(l+4,m,a)*solve(m+1,r-1,b)%md
                res%=md
    return res

s=SI()
k=II()
n=len(s)

mm=[-1]*n

d=0
dtol=defaultdict(int)

for i,c in enumerate(s):
    if c=="m":
        dtol[d]=i
        d+=1
    if c==")":
        d-=1
    if c==",":
        mm[dtol[d-1]]=i

print(solve(0,n,k)*1)
0