結果

問題 No.2031 Colored Brackets
ユーザー stngstng
提出日時 2022-08-13 16:41:19
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 739 bytes
コンパイル時間 670 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 330,140 KB
最終ジャッジ日時 2023-10-25 00:47:13
合計ジャッジ時間 5,334 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,372 KB
testcase_01 AC 36 ms
53,372 KB
testcase_02 AC 37 ms
53,372 KB
testcase_03 AC 40 ms
59,356 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
s = input()
mod = 998244353
dpb = [[0]*n for i in range(n)]
dpn = [[0]*n for i in range(n)]

cnt = 1
dpb[0][1] = 1
dpb[1][0] = 1

for i in range(1,n):
    dpn = [[0]*n for i in range(n)]
    if s[i] == "(":
        cnt += 1
        for j in range(cnt):
            dpn[cnt-1-j][j+1] += dpb[cnt-1-j][j]
            dpn[cnt-1-j][j+1] %= mod
            dpn[cnt-j][j] += dpb[cnt-1-j][j]
            dpn[cnt-j][j] %= mod
    else:
        for j in range(cnt):
            dpn[cnt-1-j][j] += dpb[cnt-j][j]
            dpn[cnt-1-j][j] %= mod
            dpn[cnt-1-j][j] += dpb[cnt-j-1][j+1]
            dpn[cnt-1-j][j] %= mod
            #print(cnt-j,j)
        cnt -= 1
    dpb = dpn[:]
    #print(dpn,dpb)
print(dpn[0][0]%mod)
0