結果

問題 No.2106 Wild Cacco
ユーザー 👑 rin204rin204
提出日時 2022-10-28 14:48:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,186 ms / 2,000 ms
コード長 912 bytes
コンパイル時間 1,089 ms
コンパイル使用メモリ 87,084 KB
実行使用メモリ 120,536 KB
最終ジャッジ日時 2023-09-19 07:21:05
合計ジャッジ時間 24,987 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,492 KB
testcase_01 AC 75 ms
71,408 KB
testcase_02 AC 73 ms
71,324 KB
testcase_03 AC 73 ms
71,260 KB
testcase_04 AC 74 ms
71,492 KB
testcase_05 AC 85 ms
76,016 KB
testcase_06 AC 85 ms
75,944 KB
testcase_07 AC 86 ms
76,312 KB
testcase_08 AC 86 ms
76,068 KB
testcase_09 AC 89 ms
76,148 KB
testcase_10 AC 84 ms
76,260 KB
testcase_11 AC 555 ms
102,848 KB
testcase_12 AC 737 ms
107,692 KB
testcase_13 AC 890 ms
110,468 KB
testcase_14 AC 687 ms
110,092 KB
testcase_15 AC 737 ms
116,580 KB
testcase_16 AC 946 ms
119,372 KB
testcase_17 AC 874 ms
119,292 KB
testcase_18 AC 788 ms
119,672 KB
testcase_19 AC 829 ms
120,536 KB
testcase_20 AC 851 ms
120,464 KB
testcase_21 AC 870 ms
119,708 KB
testcase_22 AC 698 ms
119,804 KB
testcase_23 AC 685 ms
119,524 KB
testcase_24 AC 776 ms
116,080 KB
testcase_25 AC 852 ms
118,380 KB
testcase_26 AC 1,140 ms
119,312 KB
testcase_27 AC 1,078 ms
116,380 KB
testcase_28 AC 1,092 ms
116,052 KB
testcase_29 AC 72 ms
71,488 KB
testcase_30 AC 1,136 ms
118,124 KB
testcase_31 AC 634 ms
118,380 KB
testcase_32 AC 640 ms
118,316 KB
testcase_33 AC 1,150 ms
118,512 KB
testcase_34 AC 1,186 ms
119,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

S = input()
n = len(S)

dp = [[0] * 2 for _ in range(n)]
dp[0][0] = 1

for s in S:
    ndp = [[0] * 2 for _ in range(n)]
    def f1():
        for i in range(n - 1):
            ndp[i + 1][0] += dp[i][0]
            ndp[i + 1][1] += dp[i][1]
            ndp[i + 1][0] %= MOD
            ndp[i + 1][1] %= MOD

    def f2():
        for i in range(n - 1):
            ndp[i][0] += dp[i + 1][0]
            ndp[i][1] += dp[i + 1][1]
            ndp[i][0] %= MOD
            ndp[i][1] %= MOD

    def f3():
        for i in range(n - 1):
            ndp[i + 1][0] += dp[i][0]
            ndp[i + 1][0] %= MOD

            ndp[i][1] += dp[i + 1][1] + dp[i + 1][0]
            ndp[i][1] %= MOD


    if s == "(":
        f1()
    elif s == ")":
        f2()
    elif s == "?":
        f3()
    else:
        f1()
        f2()
        f3()
    
    dp = ndp


ans = dp[0][0] + dp[0][1]
print(ans % MOD)
0