結果

問題 No.2031 Colored Brackets
ユーザー ShirotsumeShirotsume
提出日時 2022-08-03 23:23:35
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 828,364 KB
最終ジャッジ日時 2023-10-13 20:57:26
合計ジャッジ時間 5,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,340 KB
testcase_01 AC 73 ms
71,340 KB
testcase_02 AC 82 ms
76,244 KB
testcase_03 AC 92 ms
76,504 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 91 ms
76,852 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 73 ms
71,216 KB
testcase_25 AC 82 ms
76,200 KB
testcase_26 AC 71 ms
71,232 KB
testcase_27 AC 94 ms
76,980 KB
testcase_28 AC 71 ms
71,340 KB
testcase_29 AC 71 ms
71,236 KB
testcase_30 AC 69 ms
71,336 KB
testcase_31 MLE -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
n = ii()

s = input()

if n >= 500:
    exit()

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

dp[1][1][0] = dp[1][0][1] = 1
dp[1][- 2][0] = dp[1][0][- 2] = -1

for i in range(1, n):
    for j in range(n):
        for k in range(n):
            if s[i] == '(':
                dp[i + 1][j][k] += dp[i][j % (2 * n)][(k - 1) % (2 * n)] + dp[i][(j - 1) % (2 * n)][k % (2 * n)]
                dp[i + 1][j][k] %= mod
            else:
                dp[i + 1][j][k] += dp[i][j % (2 * n)][(k + 1) % (2 * n)] + dp[i][(j + 1) % (2 * n)][k % (2 * n)]
                dp[i + 1][j][k] %= mod
print(dp[n][0][0])
0