結果

問題 No.2106 Wild Cacco
ユーザー shotoyooshotoyoo
提出日時 2022-10-22 11:46:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 825 ms / 2,000 ms
コード長 1,563 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 80,592 KB
最終ジャッジ日時 2023-09-14 07:11:45
合計ジャッジ時間 15,487 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,892 KB
testcase_01 AC 100 ms
72,188 KB
testcase_02 AC 97 ms
72,100 KB
testcase_03 AC 89 ms
71,804 KB
testcase_04 AC 90 ms
72,000 KB
testcase_05 AC 109 ms
77,432 KB
testcase_06 AC 103 ms
77,656 KB
testcase_07 AC 111 ms
77,920 KB
testcase_08 AC 113 ms
78,204 KB
testcase_09 AC 109 ms
78,100 KB
testcase_10 AC 95 ms
76,280 KB
testcase_11 AC 319 ms
79,004 KB
testcase_12 AC 593 ms
79,932 KB
testcase_13 AC 677 ms
79,992 KB
testcase_14 AC 355 ms
79,672 KB
testcase_15 AC 382 ms
79,772 KB
testcase_16 AC 625 ms
80,488 KB
testcase_17 AC 568 ms
80,052 KB
testcase_18 AC 481 ms
79,896 KB
testcase_19 AC 538 ms
80,268 KB
testcase_20 AC 454 ms
80,084 KB
testcase_21 AC 449 ms
79,632 KB
testcase_22 AC 345 ms
79,688 KB
testcase_23 AC 280 ms
79,560 KB
testcase_24 AC 273 ms
79,220 KB
testcase_25 AC 279 ms
78,972 KB
testcase_26 AC 825 ms
80,228 KB
testcase_27 AC 783 ms
80,508 KB
testcase_28 AC 792 ms
80,536 KB
testcase_29 AC 92 ms
71,996 KB
testcase_30 AC 821 ms
80,592 KB
testcase_31 AC 268 ms
79,252 KB
testcase_32 AC 275 ms
79,112 KB
testcase_33 AC 820 ms
80,100 KB
testcase_34 AC 824 ms
80,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()


write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input()); SI=lambda : [ord(c)-ord("a") for c in input()]
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]

s = input()
n = len(s)
dp = [[0]*(n+1) for _ in range(2)]
dp[0][0] = 1
M = 998244353
for i in range(n):
    ndp = [[0]*(n+1) for _ in range(2)]
    if s[i]=="(":
        l = [1]
    elif s[i]==")":
        l = [-1]
    elif s[i]=="?":
        l = [2,-2]
    else:
        l = [1,2,-1,-2]
    for b in range(2):
        for j in range(n+1):
            val = dp[b][j]
            if val==0:
                continue
            for v in l:
                if v>0:
                    if v==1 or b==0:
                        ndp[b][j+1] += val
                        ndp[b][j+1] %= M
                elif j>0:
                    if v==-1:
                        ndp[b][j-1] += val
                        ndp[b][j-1] %= M
                    else:
                        # v = -2
                        ndp[1][j-1] += val
                        ndp[1][j-1] %= M
    dp = ndp
#     print(dp)
ans = dp[0][0] + dp[1][0]
print(ans%M)
0