結果
問題 | No.2031 Colored Brackets |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2022-08-05 22:46:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 160 ms / 2,000 ms |
コード長 | 471 bytes |
コンパイル時間 | 914 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 76,160 KB |
最終ジャッジ日時 | 2024-09-15 20:11:34 |
合計ジャッジ時間 | 4,010 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
n = int(input()) S = input() mod = 998244353 dp = [0]*(n+1) dp[0] = 1 count = 0 for s in S: ndp = [0]*(n+1) ad = 1 if s == "(" else -1 for i in range(n+1): if dp[i] == 0: continue if 0 <= i+ad <= n: ndp[i+ad] += dp[i] ndp[i+ad] %= mod if 0 <= count-i+ad <= n: ndp[i] += dp[i] ndp[i] %= mod dp = ndp count += ad ans = 0 if count == 0: ans = dp[0] print(ans)