結果

問題 No.2031 Colored Brackets
ユーザー tamatotamato
提出日時 2022-08-05 21:49:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 673 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 86,904 KB
実行使用メモリ 77,604 KB
最終ジャッジ日時 2023-10-13 22:30:56
合計ジャッジ時間 5,578 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,348 KB
testcase_01 AC 70 ms
71,184 KB
testcase_02 AC 75 ms
71,168 KB
testcase_03 AC 75 ms
75,860 KB
testcase_04 AC 108 ms
76,740 KB
testcase_05 AC 92 ms
76,708 KB
testcase_06 AC 98 ms
76,832 KB
testcase_07 AC 73 ms
75,488 KB
testcase_08 AC 127 ms
76,844 KB
testcase_09 AC 141 ms
77,048 KB
testcase_10 AC 158 ms
77,528 KB
testcase_11 AC 140 ms
77,180 KB
testcase_12 AC 164 ms
77,556 KB
testcase_13 AC 120 ms
77,120 KB
testcase_14 AC 167 ms
77,484 KB
testcase_15 AC 168 ms
77,604 KB
testcase_16 AC 167 ms
77,160 KB
testcase_17 AC 178 ms
77,540 KB
testcase_18 AC 158 ms
77,460 KB
testcase_19 AC 144 ms
77,192 KB
testcase_20 AC 122 ms
77,008 KB
testcase_21 AC 124 ms
77,152 KB
testcase_22 AC 129 ms
77,036 KB
testcase_23 AC 152 ms
77,200 KB
testcase_24 AC 69 ms
71,380 KB
testcase_25 AC 69 ms
71,308 KB
testcase_26 AC 68 ms
71,440 KB
testcase_27 AC 71 ms
75,724 KB
testcase_28 AC 68 ms
71,052 KB
testcase_29 AC 69 ms
71,384 KB
testcase_30 AC 70 ms
71,452 KB
testcase_31 AC 82 ms
75,568 KB
testcase_32 AC 71 ms
71,224 KB
testcase_33 AC 80 ms
75,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    S = input().rstrip('\n')

    dp = [0] * (N + 1)
    dp[0] = 1
    total_balance = 0
    for i, s in enumerate(S):
        if s == "(":
            d = 1
        else:
            d = -1
        dp_new = [0] * (2 * N + 1)
        for j in range(N + 1):
            k = total_balance - j
            if 0 <= j + d <= N:
                dp_new[j + d] = (dp_new[j + d] + dp[j]) % mod
            if 0 <= k + d <= N:
                dp_new[j] = (dp_new[j] + dp[j]) % mod
        total_balance += d
        dp = dp_new
    print(dp[0])


if __name__ == '__main__':
    main()
0