結果

問題 No.2031 Colored Brackets
ユーザー tassei903tassei903
提出日時 2022-08-08 13:14:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 81,544 KB
実行使用メモリ 109,780 KB
最終ジャッジ日時 2023-10-19 03:38:00
合計ジャッジ時間 4,883 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,352 KB
testcase_01 AC 40 ms
53,352 KB
testcase_02 AC 39 ms
53,352 KB
testcase_03 AC 49 ms
61,988 KB
testcase_04 AC 94 ms
86,076 KB
testcase_05 AC 66 ms
68,224 KB
testcase_06 AC 73 ms
72,572 KB
testcase_07 AC 41 ms
53,352 KB
testcase_08 AC 110 ms
87,220 KB
testcase_09 AC 119 ms
87,508 KB
testcase_10 AC 153 ms
107,300 KB
testcase_11 AC 119 ms
87,264 KB
testcase_12 AC 156 ms
109,576 KB
testcase_13 AC 106 ms
87,468 KB
testcase_14 AC 159 ms
109,568 KB
testcase_15 AC 157 ms
109,568 KB
testcase_16 AC 159 ms
109,288 KB
testcase_17 AC 185 ms
109,288 KB
testcase_18 AC 132 ms
109,780 KB
testcase_19 AC 105 ms
87,576 KB
testcase_20 AC 94 ms
87,508 KB
testcase_21 AC 97 ms
87,524 KB
testcase_22 AC 98 ms
87,516 KB
testcase_23 AC 132 ms
109,080 KB
testcase_24 AC 40 ms
53,352 KB
testcase_25 AC 39 ms
53,352 KB
testcase_26 AC 40 ms
53,352 KB
testcase_27 AC 40 ms
53,352 KB
testcase_28 AC 39 ms
53,352 KB
testcase_29 AC 39 ms
53,352 KB
testcase_30 AC 39 ms
53,352 KB
testcase_31 AC 52 ms
64,120 KB
testcase_32 AC 39 ms
53,352 KB
testcase_33 AC 53 ms
64,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
n = ni()
s = [[-1,1][i == "("]for i in input()]
d = [0]
for i in range(n):
    d.append(d[-1] + s[i])

dp = [[0 for j in range(n//2+1)]for i in range(n+1)]
dp[0][0] = 1
mod = 998244353
for i in range(n):
    for j in range(n//2+1):
        now = dp[i][j]
        if now == 0:
            continue
        ni = i + 1
        # ()
        nj = j + s[i]
        nk = d[i+1] - nj
        if 0 <= nj <= n//2 and 0 <= nk <= n//2:
            dp[ni][nj] += now
            dp[ni][nj] %= mod
        # []
        nj = j
        nk = d[i+1] - nj
        if 0 <= nj <= n//2 and 0 <= nk <= n//2:
            dp[ni][nj] += now
            dp[ni][nj] %= mod
print(dp[-1][0])
0