結果

問題 No.2106 Wild Cacco
ユーザー chineristACchineristAC
提出日時 2022-10-21 22:01:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 748 ms / 2,000 ms
コード長 1,588 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 145,556 KB
最終ジャッジ日時 2023-09-13 22:20:04
合計ジャッジ時間 20,236 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
74,768 KB
testcase_01 AC 120 ms
74,396 KB
testcase_02 AC 129 ms
74,620 KB
testcase_03 AC 125 ms
74,576 KB
testcase_04 AC 125 ms
74,736 KB
testcase_05 AC 138 ms
79,812 KB
testcase_06 AC 146 ms
79,964 KB
testcase_07 AC 160 ms
81,032 KB
testcase_08 AC 161 ms
81,256 KB
testcase_09 AC 167 ms
81,800 KB
testcase_10 AC 163 ms
81,392 KB
testcase_11 AC 498 ms
130,120 KB
testcase_12 AC 626 ms
132,976 KB
testcase_13 AC 661 ms
135,720 KB
testcase_14 AC 620 ms
138,956 KB
testcase_15 AC 609 ms
142,080 KB
testcase_16 AC 748 ms
145,100 KB
testcase_17 AC 717 ms
144,628 KB
testcase_18 AC 676 ms
145,320 KB
testcase_19 AC 707 ms
145,556 KB
testcase_20 AC 674 ms
144,368 KB
testcase_21 AC 688 ms
145,556 KB
testcase_22 AC 597 ms
144,712 KB
testcase_23 AC 616 ms
145,008 KB
testcase_24 AC 646 ms
141,636 KB
testcase_25 AC 691 ms
145,436 KB
testcase_26 AC 732 ms
144,692 KB
testcase_27 AC 702 ms
141,076 KB
testcase_28 AC 699 ms
141,736 KB
testcase_29 AC 113 ms
74,408 KB
testcase_30 AC 697 ms
144,172 KB
testcase_31 AC 489 ms
144,188 KB
testcase_32 AC 466 ms
144,348 KB
testcase_33 AC 738 ms
144,624 KB
testcase_34 AC 742 ms
144,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict
from heapq import heapify,heappop,heappush
from itertools import combinations, permutations
from math import log,gcd


input = lambda :sys.stdin.readline()
mi = lambda :map(int,input().split())
li = lambda :list(mi())


mod = 998244353

s = input().rstrip()
n = len(s)

dp_left = [[0] * (n//2+1) for i in range(n+1)]
dp_left[0][0] = 1
for i in range(n):
    for j in range(n//2+1):
        if (s[i] == "(" or s[i] == ".") and j+1 <= n//2:
            dp_left[i+1][j+1] += dp_left[i][j]
            dp_left[i+1][j+1] %= mod
        if (s[i] == ")" or s[i] == ".") and 0 <= j-1:
            dp_left[i+1][j-1] += dp_left[i][j]
            dp_left[i+1][j-1] %= mod
        if (s[i] == "?" or s[i] == ".") and j+1 <= n//2:
            dp_left[i+1][j+1] += dp_left[i][j]
            dp_left[i+1][j+1] %= mod

res = dp_left[n][0]


#print(res,dp_left)

dp_right = [0] * (n//2+1)
dp_right[0] = 1

for i in range(n)[::-1]:
    ndp = [0] * (n//2+1)
    
    for j in range(n//2+1):
        if (s[i] == ")" or s[i] == ".") and j+1 <= n//2:
            ndp[j+1] += dp_right[j]
            ndp[j+1] %= mod
            
        if (s[i] == "(" or s[i] == ".") and 0 <= j-1:
            ndp[j-1] += dp_right[j]
            ndp[j-1] %= mod
            
        if (s[i] == "?" or s[i] == ".") and j+1 <= n//2:
            ndp[j+1] += dp_right[j]
            ndp[j+1] %= mod

            

            tmp = dp_left[i][j+1] * dp_right[j] % mod
            res = (res + tmp) % mod
            

    dp_right = ndp
    
    




print(res)
0