CF1906L.Palindromic Parentheses

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:1024MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Construct a parentheses sequence consisting of NN characters such that it is balanced and the length of its longest palindromic subsequence (LPS) is exactly KK. Determine whether such a construction is possible. If there are several possible sequences, construct any of them.

A parentheses sequence consists of only character ( and ). A parentheses sequence is balanced if each character ( has a corresponding character ) and the pairs of parentheses are properly nested. For example, (), (()), (())(), and ((())()) are balanced. However, )(, ((), and ()) are not balanced.

A sequence is palindromic if it reads the same backwards as forwards. For example, ((, ), ())(, and (()(( are palindromic. However, (), )(, and (()) are not palindromic.

A subsequence can be derived from another sequence by removing zero or more characters without changing the order of the remaining characters. For example, (, ))), ())(, and (())() are subsequence of (())(). However, )(( and ((())) are not subsequence of (())().

The longest palindromic subsequence (LPS) of a sequence is a subsequence with the maximum number of characters, derived from that sequence and it is palindromic. For example, the LPS of sequence (())() is ())(, which can be obtained by removing the second and sixth characters. Therefore, the length of the LPS of (())() is 44.

构造一个由 NN 个字符组成的括号序列,使其为合法括号序列(即“平衡的”),且其最长回文子序列(LPS)的长度恰好为 KK。判断这样的构造是否可行;若可行,输出任意一个满足条件的序列。

括号序列仅由字符 ( 和 ) 组成。一个括号序列是平衡的,当且仅当每个 ( 都有唯一对应的 ),且所有括号对均正确嵌套。例如,()、(())、(())() 和 ((())()) 是平衡的;而 )(、(() 和 ()) 不是平衡的。

一个序列是回文的,当且仅当它正读与反读完全相同。例如,((、)、)(() 和 (()(( 是回文的;而 ()、)( 和 (()) 不是回文的。

一个子序列可通过从原序列中删除零个或多个字符(不改变剩余字符的相对顺序)得到。例如,(、)))、)(() 和 (())() 都是 (())() 的子序列;而 )(( 和 ((())) 不是 (())() 的子序列。

一个序列的最长回文子序列(LPS) 是指该序列的所有回文子序列中长度最大的一个。例如,序列 (())() 的 LPS 是 )(()(通过删去第 2 个和第 6 个字符得到),因此 (())() 的 LPS 长度为 44。

输入格式

Input consists of two integers NN KK (2≤N≤2000;1≤K≤N2 \leq N \leq 2000; 1 \leq K \leq N). NN is an even number.

输入包含两个整数 NN 和 KK(2≤N≤20002 \leq N \leq 2000;1≤K≤N1 \leq K \leq N)。其中 NN 为偶数。

输出格式

If there is no such parentheses sequence such that it is balanced and the length of its LPS is exactly KK, then output -1.

Otherwise, output a string of NN characters, representing the parentheses sequence. If there are several possible answers, output any of them.

如果不存在长度为 NN 的平衡括号序列,使得其最长回文子串(LPS)的长度恰好为 KK,则输出 -1。

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

输入输出样例

  • 输入#1

    6 4

    输出#1

    (())()
  • 输入#2

    6 3

    输出#2

    (()())
  • 输入#3

    4 1

    输出#3

    -1
  • 输入#4

    14 11

    输出#4

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

说明/提示

Explanation for the sample input/output #2

The LPS of (()()) is either ((( by removing all ) characters, or ))) by removing all ( characters.

The output ((())) also satisfies the requirements.

Explanation for the sample input/output #3

The only possible balanced parentheses sequences are (()) and ()(). The length of the LPS of (()) and ()() are 22 and 33, respectively.

Explanation for the sample input/output #4

The LPS of ()((())()())() is )())()())(), which can be obtained by removing the first, fourth, and fifth characters.

样例输入/输出 #2 的说明

(()()) 的最长回文子序列(LPS)可以是 ((((通过移除所有 ) 字符得到),也可以是 )))(通过移除所有 ( 字符得到)。

输出 ((())) 同样满足要求。

样例输入/输出 #3 的说明

唯一可能的合法括号序列是 (()) 和 ()()。它们的最长回文子序列(LPS)长度分别为 22 和 33。

样例输入/输出 #4 的说明

()((())()())() 的最长回文子序列(LPS)是 )())()())(),可通过移除第 1、第 4 和第 5 个字符得到。

输入解题思路,AI测评打分。不知道怎么写?

首页