結果

問題 No.2031 Colored Brackets
ユーザー roarisroaris
提出日時 2022-08-05 22:47:53
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,012 ms / 2,000 ms
コード長 586 bytes
コンパイル時間 908 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 82,716 KB
最終ジャッジ日時 2023-10-14 00:22:46
合計ジャッジ時間 11,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,496 KB
testcase_01 AC 92 ms
71,584 KB
testcase_02 AC 93 ms
71,324 KB
testcase_03 AC 94 ms
71,356 KB
testcase_04 AC 290 ms
78,440 KB
testcase_05 AC 187 ms
78,492 KB
testcase_06 AC 211 ms
78,404 KB
testcase_07 AC 93 ms
71,604 KB
testcase_08 AC 344 ms
78,548 KB
testcase_09 AC 421 ms
78,920 KB
testcase_10 AC 533 ms
79,820 KB
testcase_11 AC 429 ms
78,812 KB
testcase_12 AC 542 ms
79,360 KB
testcase_13 AC 335 ms
78,680 KB
testcase_14 AC 554 ms
79,152 KB
testcase_15 AC 643 ms
79,296 KB
testcase_16 AC 556 ms
79,388 KB
testcase_17 AC 1,012 ms
82,716 KB
testcase_18 AC 123 ms
77,616 KB
testcase_19 AC 138 ms
78,500 KB
testcase_20 AC 132 ms
78,364 KB
testcase_21 AC 134 ms
78,400 KB
testcase_22 AC 140 ms
78,516 KB
testcase_23 AC 140 ms
78,532 KB
testcase_24 AC 93 ms
71,384 KB
testcase_25 AC 92 ms
71,348 KB
testcase_26 AC 93 ms
71,596 KB
testcase_27 AC 92 ms
71,616 KB
testcase_28 AC 94 ms
71,672 KB
testcase_29 AC 91 ms
71,596 KB
testcase_30 AC 92 ms
71,716 KB
testcase_31 AC 125 ms
78,176 KB
testcase_32 AC 91 ms
71,524 KB
testcase_33 AC 125 ms
78,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

N = int(input())
S = input()[:-1]
dp = defaultdict(int)
dp[(0, 0)] = 1
MOD = 998244353

for Si in S:
    ndp = defaultdict(int)
    
    if Si=='(':
        for p in dp:
            ndp[(p[0]+1, p[1])] += dp[p]
            ndp[(p[0], p[1]+1)] += dp[p]
    else:
        for p in dp:
            if p[0]>0:
                ndp[(p[0]-1, p[1])] += dp[p]
            
            if p[1]>0:
                ndp[(p[0], p[1]-1)] += dp[p]
    
    dp = ndp
    
    for p in dp:
        dp[p] %= MOD

print(sum(dp.values())%MOD)
0