QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#10569. Palindromic Parentheses

الإحصائيات

构造一个长度为 $N$ 的括号序列,使其满足平衡且其最长回文子序列(LPS)的长度恰好为 $K$。判断是否存在这样的构造。如果存在多种可能的序列,输出其中任意一个。

括号序列仅由字符 () 组成。如果每个 ( 都有对应的 ) 且括号嵌套正确,则该括号序列是平衡的。例如,(), (()), ()()(()()) 是平衡的。而 )(, (()()) 不是平衡的。

如果一个序列从后往前读与从前往后读相同,则该序列是回文的。例如,((, )), ()()(()) 是回文的。而 (), )((() 不是回文的。

子序列可以通过从另一个序列中删除零个或多个字符(不改变剩余字符的顺序)得到。例如,(, ), ())(())( 的子序列。而 ))(((( 不是 ())( 的子序列。

序列的最长回文子序列(LPS)是指从该序列中导出的长度最大的回文子序列。例如,序列 ()(()) 的 LPS 是 (()),可以通过删除第二个和第六个字符得到。因此,()(()) 的 LPS 长度为 4。

输入格式

输入包含两个整数 $N$ 和 $K$ ($2 \le N \le 2000$; $1 \le K \le N$)。$N$ 为偶数。

输出格式

如果不存在满足平衡且 LPS 长度恰好为 $K$ 的括号序列,则输出 -1

否则,输出一个长度为 $N$ 的字符串,表示该括号序列。如果存在多个可能的答案,输出其中任意一个。

样例

输入 1

6 4

输出 1

(())()

输入 2

6 3

输出 2

((()))

说明 2

((())) 的 LPS 可以是删除所有 ) 字符后得到的 (((,或者删除所有 ( 字符后得到的 )))。输出 ((())) 也满足要求。

输入 3

4 1

输出 3

-1

说明 3

唯一的平衡括号序列是 (())()()(())()() 的 LPS 长度分别为 2 和 3。

输入 4

14 11

输出 4

(()(()()()()))

说明 4

(()(()()()())) 的 LPS 是 ((((((()))))),可以通过删除第一个、第四个和第五个字符得到。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.