結果

問題 No.2031 Colored Brackets
ユーザー shobonvipshobonvip
提出日時 2022-08-06 00:13:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 137,512 KB
最終ジャッジ日時 2023-10-14 02:32:00
合計ジャッジ時間 7,016 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,180 KB
testcase_01 AC 74 ms
71,216 KB
testcase_02 AC 74 ms
71,144 KB
testcase_03 AC 81 ms
75,996 KB
testcase_04 AC 142 ms
91,452 KB
testcase_05 AC 114 ms
85,376 KB
testcase_06 AC 126 ms
89,876 KB
testcase_07 AC 76 ms
71,268 KB
testcase_08 AC 185 ms
113,088 KB
testcase_09 AC 201 ms
114,492 KB
testcase_10 AC 246 ms
137,512 KB
testcase_11 AC 203 ms
114,416 KB
testcase_12 AC 253 ms
137,364 KB
testcase_13 AC 184 ms
109,172 KB
testcase_14 AC 258 ms
137,336 KB
testcase_15 AC 257 ms
137,252 KB
testcase_16 AC 258 ms
137,408 KB
testcase_17 AC 273 ms
137,324 KB
testcase_18 AC 240 ms
137,212 KB
testcase_19 AC 235 ms
133,984 KB
testcase_20 AC 185 ms
112,972 KB
testcase_21 AC 181 ms
114,328 KB
testcase_22 AC 184 ms
114,440 KB
testcase_23 AC 241 ms
137,292 KB
testcase_24 AC 72 ms
71,344 KB
testcase_25 AC 73 ms
71,064 KB
testcase_26 AC 73 ms
71,224 KB
testcase_27 AC 71 ms
71,268 KB
testcase_28 AC 72 ms
71,228 KB
testcase_29 AC 73 ms
71,276 KB
testcase_30 AC 75 ms
71,152 KB
testcase_31 AC 87 ms
75,976 KB
testcase_32 AC 73 ms
71,228 KB
testcase_33 AC 87 ms
76,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
n = int(input())
s = input()
dp = [[0] * (n+1) for i in range(n+1)]
dp[0][0] = 1

tmp = 0
for i in range(n):
	if s[i] == "(":
		tmp += 1
		for j in range(n+1):
			if j+1 <= n:
				dp[i+1][j+1] += dp[i][j]
				dp[i+1][j+1] %= mod
			if tmp-j >= 0:
				dp[i+1][j] += dp[i][j]
				dp[i+1][j] %= mod
	else:
		tmp -= 1
		for j in range(n+1):
			if j-1 >= 0:
				dp[i+1][j-1] += dp[i][j]
				dp[i+1][j-1] %= mod
			if tmp-j >= 0:
				dp[i+1][j] += dp[i][j]
				dp[i+1][j] %= mod

print(dp[n][0])
0