結果

問題 No.2031 Colored Brackets
ユーザー 👑 KazunKazun
提出日時 2022-08-05 22:18:15
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 86,988 KB
実行使用メモリ 112,744 KB
最終ジャッジ日時 2023-10-13 23:29:27
合計ジャッジ時間 6,755 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,212 KB
testcase_01 AC 67 ms
71,356 KB
testcase_02 AC 64 ms
71,072 KB
testcase_03 AC 75 ms
76,040 KB
testcase_04 AC 122 ms
87,976 KB
testcase_05 AC 99 ms
76,364 KB
testcase_06 AC 110 ms
83,600 KB
testcase_07 AC 67 ms
70,944 KB
testcase_08 AC 144 ms
89,500 KB
testcase_09 AC 159 ms
89,992 KB
testcase_10 AC 196 ms
108,724 KB
testcase_11 AC 160 ms
89,356 KB
testcase_12 AC 204 ms
111,920 KB
testcase_13 AC 137 ms
89,908 KB
testcase_14 AC 206 ms
112,740 KB
testcase_15 AC 207 ms
112,744 KB
testcase_16 AC 210 ms
112,500 KB
testcase_17 AC 211 ms
112,536 KB
testcase_18 AC 206 ms
112,604 KB
testcase_19 AC 185 ms
105,544 KB
testcase_20 AC 142 ms
89,740 KB
testcase_21 AC 148 ms
89,964 KB
testcase_22 AC 148 ms
89,984 KB
testcase_23 AC 195 ms
110,720 KB
testcase_24 AC 65 ms
71,064 KB
testcase_25 AC 64 ms
71,328 KB
testcase_26 AC 65 ms
70,968 KB
testcase_27 AC 68 ms
71,140 KB
testcase_28 AC 64 ms
71,424 KB
testcase_29 AC 67 ms
71,256 KB
testcase_30 AC 66 ms
71,316 KB
testcase_31 AC 78 ms
76,528 KB
testcase_32 AC 64 ms
71,136 KB
testcase_33 AC 78 ms
76,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
S=["*"]+[1 if s=="(" else -1 for s in input()]

T=[0]*(N+1)
for i in range(1,N+1):
    T[i]=T[i-1]+S[i]

Mod=998244353
DP=[[0]*(N//2+1) for _ in range(N+1)]; DP[0][0]=1

for i in range(1,N+1):
    for j in range(N//2+1):
        # 赤に塗る
        if S[i]==1:
            if j-1>=0:
                DP[i][j]+=DP[i-1][j-1]
        else:
            if j+1<=N//2:
                DP[i][j]+=DP[i-1][j+1]

        # 青に塗る
        if S[i]==1:
            if T[i]-j<=N//2:
                DP[i][j]+=DP[i-1][j]
        else:
            if T[i]-j>=0:
                DP[i][j]+=DP[i-1][j]

    for j in range(N//2+1):
        DP[i][j]%=Mod

print(DP[N][0])
0