結果

問題 No.2031 Colored Brackets
ユーザー EguyEguy
提出日時 2022-08-05 22:43:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 86,956 KB
実行使用メモリ 137,524 KB
最終ジャッジ日時 2023-10-14 00:15:41
合計ジャッジ時間 6,319 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,288 KB
testcase_01 AC 73 ms
70,916 KB
testcase_02 AC 73 ms
71,108 KB
testcase_03 AC 72 ms
71,052 KB
testcase_04 AC 114 ms
91,464 KB
testcase_05 AC 90 ms
76,572 KB
testcase_06 AC 106 ms
89,884 KB
testcase_07 AC 73 ms
70,920 KB
testcase_08 AC 134 ms
113,144 KB
testcase_09 AC 141 ms
114,460 KB
testcase_10 AC 169 ms
137,144 KB
testcase_11 AC 141 ms
114,508 KB
testcase_12 AC 159 ms
137,336 KB
testcase_13 AC 130 ms
109,528 KB
testcase_14 AC 170 ms
137,444 KB
testcase_15 AC 173 ms
137,500 KB
testcase_16 AC 169 ms
137,396 KB
testcase_17 AC 184 ms
137,288 KB
testcase_18 AC 151 ms
137,524 KB
testcase_19 AC 152 ms
134,000 KB
testcase_20 AC 125 ms
113,192 KB
testcase_21 AC 131 ms
114,488 KB
testcase_22 AC 127 ms
114,348 KB
testcase_23 AC 155 ms
137,328 KB
testcase_24 AC 73 ms
71,540 KB
testcase_25 AC 72 ms
71,088 KB
testcase_26 AC 73 ms
71,180 KB
testcase_27 AC 76 ms
71,228 KB
testcase_28 AC 72 ms
71,372 KB
testcase_29 AC 73 ms
71,420 KB
testcase_30 AC 71 ms
71,576 KB
testcase_31 AC 84 ms
75,904 KB
testcase_32 AC 74 ms
71,252 KB
testcase_33 AC 83 ms
76,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, math
sys.setrecursionlimit(1000000)
INF = 1 << 100
#mod = 1000000007
mod = 998244353
input = lambda: sys.stdin.readline().rstrip()
li = lambda: list(map(int, input().split()))

N = int(input())
S = list(input())

dp = [[0] * (N+2) for _ in range(N+1)]
dp[0][0] = 1

x = 0
y = 0
for i in range(N):
    if S[i] == '(':
        x += 1
        for j in range(x-y+1):
            dp[i+1][j+1] += dp[i][j]
            dp[i+1][j] += dp[i][j]
            dp[i+1][j+1] %= mod
            dp[i+1][j] %= mod
    else:
        y += 1
        for j in range(x-y+1):
            dp[i+1][j] += dp[i][j+1]
            dp[i+1][j] += dp[i][j]
            dp[i+1][j] %= mod
            dp[i+1][j] %= mod

print(dp[-1][0] % mod)
0