結果
| 問題 |
No.2031 Colored Brackets
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-08-20 15:39:23 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 346 ms / 2,000 ms |
| コード長 | 649 bytes |
| コンパイル時間 | 274 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 77,696 KB |
| 最終ジャッジ日時 | 2024-10-09 08:18:19 |
| 合計ジャッジ時間 | 4,772 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
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))