結果

問題 No.2031 Colored Brackets
ユーザー first_vilfirst_vil
提出日時 2022-08-05 22:06:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 993 bytes
コンパイル時間 1,223 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 77,688 KB
最終ジャッジ日時 2023-10-13 23:09:13
合計ジャッジ時間 5,883 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,328 KB
testcase_01 AC 70 ms
71,408 KB
testcase_02 AC 75 ms
71,396 KB
testcase_03 AC 83 ms
75,984 KB
testcase_04 AC 124 ms
77,288 KB
testcase_05 AC 97 ms
76,980 KB
testcase_06 AC 109 ms
77,404 KB
testcase_07 AC 73 ms
75,868 KB
testcase_08 AC 145 ms
77,192 KB
testcase_09 AC 165 ms
77,580 KB
testcase_10 AC 186 ms
77,688 KB
testcase_11 AC 161 ms
77,428 KB
testcase_12 AC 195 ms
77,528 KB
testcase_13 AC 139 ms
77,288 KB
testcase_14 AC 194 ms
77,456 KB
testcase_15 AC 205 ms
77,332 KB
testcase_16 AC 196 ms
77,340 KB
testcase_17 AC 219 ms
77,540 KB
testcase_18 AC 174 ms
77,368 KB
testcase_19 AC 161 ms
77,664 KB
testcase_20 AC 143 ms
77,448 KB
testcase_21 AC 136 ms
77,656 KB
testcase_22 AC 143 ms
77,272 KB
testcase_23 AC 172 ms
77,372 KB
testcase_24 AC 72 ms
71,344 KB
testcase_25 AC 71 ms
71,204 KB
testcase_26 AC 78 ms
71,324 KB
testcase_27 AC 81 ms
75,880 KB
testcase_28 AC 74 ms
71,216 KB
testcase_29 AC 72 ms
71,516 KB
testcase_30 AC 72 ms
71,344 KB
testcase_31 AC 87 ms
76,108 KB
testcase_32 AC 73 ms
71,216 KB
testcase_33 AC 85 ms
76,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heapify, heappop, heappush
import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
# mod = int(1e9 + 7)
mod = 998244353


n = ii()
a = [1 if c == "(" else -1 for c in input()]
dp = [0] * (n + 1)  # dp[x]= 赤の合計がxで青の合計がacc-x
dp[0] = 1
acc = 0
for i in range(n):
    nxt = [0] * (n + 1)
    for x in range(n + 1):
        y = acc - x
        if 0 <= x + a[i] <= n:
            nxt[x + a[i]] += dp[x]
            if nxt[x + a[i]] >= mod:
                nxt[x + a[i]] -= mod
        if 0 <= y + a[i] <= n:
            nxt[x] += dp[x]
            if nxt[x] >= mod:
                nxt[x] -= mod
    dp = nxt
    acc += a[i]
print(dp[0])
0