結果

問題 No.2031 Colored Brackets
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-08-05 22:46:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 471 bytes
コンパイル時間 2,270 ms
コンパイル使用メモリ 86,888 KB
実行使用メモリ 77,244 KB
最終ジャッジ日時 2023-10-14 00:21:02
合計ジャッジ時間 5,481 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,196 KB
testcase_01 AC 72 ms
71,184 KB
testcase_02 AC 73 ms
71,344 KB
testcase_03 AC 76 ms
76,228 KB
testcase_04 AC 106 ms
77,144 KB
testcase_05 AC 91 ms
76,492 KB
testcase_06 AC 99 ms
76,740 KB
testcase_07 AC 74 ms
75,676 KB
testcase_08 AC 111 ms
77,108 KB
testcase_09 AC 121 ms
77,152 KB
testcase_10 AC 136 ms
77,032 KB
testcase_11 AC 124 ms
77,064 KB
testcase_12 AC 135 ms
76,756 KB
testcase_13 AC 111 ms
76,956 KB
testcase_14 AC 140 ms
77,104 KB
testcase_15 AC 142 ms
77,244 KB
testcase_16 AC 133 ms
77,224 KB
testcase_17 AC 173 ms
77,176 KB
testcase_18 AC 123 ms
77,100 KB
testcase_19 AC 114 ms
76,972 KB
testcase_20 AC 105 ms
76,920 KB
testcase_21 AC 104 ms
77,224 KB
testcase_22 AC 108 ms
77,232 KB
testcase_23 AC 118 ms
76,756 KB
testcase_24 AC 74 ms
71,328 KB
testcase_25 AC 72 ms
71,312 KB
testcase_26 AC 73 ms
70,896 KB
testcase_27 AC 73 ms
75,560 KB
testcase_28 AC 72 ms
71,372 KB
testcase_29 AC 70 ms
71,424 KB
testcase_30 AC 72 ms
71,080 KB
testcase_31 AC 86 ms
76,200 KB
testcase_32 AC 71 ms
71,112 KB
testcase_33 AC 83 ms
76,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
S = input()
mod = 998244353

dp = [0]*(n+1)
dp[0] = 1

count = 0

for s in S:
    ndp = [0]*(n+1)
    ad = 1 if s == "(" else -1

    for i in range(n+1):
        if dp[i] == 0:
            continue

        if 0 <= i+ad <= n:
            ndp[i+ad] += dp[i]
            ndp[i+ad] %= mod

        if 0 <= count-i+ad <= n:
            ndp[i] += dp[i]
            ndp[i] %= mod
    dp = ndp
    count += ad

ans = 0
if count == 0:
    ans = dp[0]
print(ans)
0