結果

問題 No.2031 Colored Brackets
ユーザー 👑 rin204rin204
提出日時 2022-08-20 15:39:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 326 ms / 2,000 ms
コード長 649 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 77,824 KB
最終ジャッジ日時 2024-04-17 14:18:26
合計ジャッジ時間 4,893 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,968 KB
testcase_01 AC 41 ms
51,712 KB
testcase_02 AC 41 ms
51,712 KB
testcase_03 AC 43 ms
52,480 KB
testcase_04 AC 117 ms
75,520 KB
testcase_05 AC 89 ms
76,032 KB
testcase_06 AC 96 ms
75,904 KB
testcase_07 AC 41 ms
51,840 KB
testcase_08 AC 137 ms
75,776 KB
testcase_09 AC 161 ms
76,032 KB
testcase_10 AC 195 ms
76,160 KB
testcase_11 AC 162 ms
76,032 KB
testcase_12 AC 203 ms
75,904 KB
testcase_13 AC 136 ms
76,032 KB
testcase_14 AC 203 ms
75,904 KB
testcase_15 AC 203 ms
76,288 KB
testcase_16 AC 196 ms
76,416 KB
testcase_17 AC 326 ms
77,824 KB
testcase_18 AC 60 ms
63,872 KB
testcase_19 AC 71 ms
66,816 KB
testcase_20 AC 64 ms
65,152 KB
testcase_21 AC 67 ms
66,304 KB
testcase_22 AC 67 ms
66,816 KB
testcase_23 AC 70 ms
67,456 KB
testcase_24 AC 40 ms
51,712 KB
testcase_25 AC 39 ms
51,456 KB
testcase_26 AC 39 ms
51,712 KB
testcase_27 AC 39 ms
51,712 KB
testcase_28 AC 40 ms
51,712 KB
testcase_29 AC 41 ms
51,840 KB
testcase_30 AC 42 ms
51,712 KB
testcase_31 AC 60 ms
63,488 KB
testcase_32 AC 40 ms
51,712 KB
testcase_33 AC 58 ms
63,360 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

n = int(input())
S = input()
dp = {0:1}
for s in S:
    ndp = {}
    for rb, v in dp.items():
        r = rb // n
        b = rb - r * n
        if s == "(":
            x = rb + n
            ndp[x] = ndp.get(x, 0) + v
            ndp[x] %= MOD
            x = rb + 1
            ndp[x] = ndp.get(x, 0) + v
            ndp[x] %= MOD
        else:
            if r >= 1:
                x = rb - n
                ndp[x] = ndp.get(x, 0) + v
                ndp[x] %= MOD
            if b >= 1:
                x = rb - 1
                ndp[x] = ndp.get(x, 0) + v
                ndp[x] %= MOD
    dp = ndp
    
print(ndp.get(0, 0))
0