結果
| 問題 | No.2031 Colored Brackets |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-05 22:46:44 |
| 言語 | PyPy3 (7.3.23 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 115 ms / 2,000 ms |
| + 605µs | |
| コード長 | 471 bytes |
| 記録 | |
| コンパイル時間 | 232 ms |
| コンパイル使用メモリ | 96,108 KB |
| 実行使用メモリ | 84,224 KB |
| 最終ジャッジ日時 | 2026-08-28 05:50:59 |
| 合計ジャッジ時間 | 4,867 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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)