結果

問題 No.2031 Colored Brackets
ユーザー stngstng
提出日時 2022-08-13 17:07:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,049 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 81,468 KB
実行使用メモリ 267,872 KB
最終ジャッジ日時 2023-10-25 01:10:11
合計ジャッジ時間 5,251 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,480 KB
testcase_01 AC 42 ms
53,428 KB
testcase_02 AC 43 ms
55,476 KB
testcase_03 AC 61 ms
70,436 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 #

import copy
n = int(input())
s = input()
mod = 998244353
dpb = [[0]*(n//2+1) for i in range((n//2+1))]
dpn = [[0]*(n//2+1) for i in range((n//2+1))]

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

for i in range(1,n):
    #dpn = ori[:]
    #print(dpn,ori,"ori_??")
    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 = copy.deepcopy(dpn)
    #print(dpn,dpb)
    if s[i] == "(":
        for j in range(cnt):
            dpn[cnt-1-j][j+1] = 0
            dpn[cnt-j][j] = 0
    else:
        for j in range(cnt):
            dpn[cnt-1-j][j] = 0
            dpn[cnt-1-j][j] = 0
        cnt -= 1
            
print(dpb[0][0]%mod)
0