Logo
(追記) (追記ここまで)

32087번 - Palindromic Parentheses 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB80444167.213%

문제

Construct a parentheses sequence consisting of $N$ characters such that it is balanced and the length of its longest palindromic subsequence (LPS) is exactly $K$. 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 4ドル$.

입력

Input consists of two integers $N$ $K$ (2ドル ≤ N ≤ 2000$; 1ドル ≤ K ≤ N$). $N$ is an even number.

출력

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

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

제한

예제 입력 1

6 4

예제 출력 1

(())()

예제 입력 2

6 3

예제 출력 2

(()())

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

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

예제 입력 3

4 1

예제 출력 3

-1

The only possible balanced parentheses sequences are (()) and ()(). The length of the LPS of (()) and ()() are 2ドル$ and 3ドル,ドル respectively.

예제 입력 4

14 11

예제 출력 4

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

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

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2023 ICPC Asia Jakarta Regional Contest L번

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2024 ICPC Asia Jakarta Regional Contest 연습 세션 PB번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /