結果

問題 No.2031 Colored Brackets
ユーザー ああいいああいい
提出日時 2022-08-07 17:12:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 588 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 81,628 KB
実行使用メモリ 75,644 KB
最終ジャッジ日時 2023-10-17 12:03:54
合計ジャッジ時間 4,571 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,336 KB
testcase_01 AC 35 ms
53,336 KB
testcase_02 AC 35 ms
53,336 KB
testcase_03 AC 40 ms
59,744 KB
testcase_04 AC 73 ms
75,432 KB
testcase_05 AC 64 ms
70,416 KB
testcase_06 AC 64 ms
72,448 KB
testcase_07 AC 37 ms
53,336 KB
testcase_08 AC 85 ms
75,484 KB
testcase_09 AC 92 ms
75,488 KB
testcase_10 AC 101 ms
75,508 KB
testcase_11 AC 92 ms
75,624 KB
testcase_12 AC 102 ms
75,492 KB
testcase_13 AC 81 ms
75,436 KB
testcase_14 AC 105 ms
75,524 KB
testcase_15 AC 106 ms
75,508 KB
testcase_16 AC 103 ms
75,492 KB
testcase_17 AC 119 ms
75,644 KB
testcase_18 AC 87 ms
75,432 KB
testcase_19 AC 83 ms
75,444 KB
testcase_20 AC 75 ms
75,452 KB
testcase_21 AC 77 ms
75,480 KB
testcase_22 AC 78 ms
75,484 KB
testcase_23 AC 87 ms
75,496 KB
testcase_24 AC 36 ms
53,336 KB
testcase_25 AC 35 ms
53,336 KB
testcase_26 AC 36 ms
53,336 KB
testcase_27 AC 37 ms
53,336 KB
testcase_28 AC 36 ms
53,336 KB
testcase_29 AC 35 ms
53,336 KB
testcase_30 AC 35 ms
53,336 KB
testcase_31 AC 54 ms
66,312 KB
testcase_32 AC 36 ms
53,336 KB
testcase_33 AC 52 ms
64,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = input()
P = 998244353

C = (N // 2) + 1
dp = [0] * C
dp[0] = 1
now = 0
for s in S:
    nx = [0] * C
    for red in range(C):
        blue = now - red
        if blue < 0:continue
        if s == "(":
            if red < C - 1:
                nx[red + 1] += dp[red]
            nx[red] += dp[red]
        else:
            if red > 0:
                nx[red - 1] += dp[red]
            if blue > 0:
                nx[red] += dp[red]
    for red in range(C):
        nx[red] %= P
    dp = nx
    if s == "(":
        now += 1
    else:
        now -= 1
print(dp[0])
0