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

18908번 - Brackets 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB45222261.111%

문제

There are 2ドルn$ elements divided into $n$ pairs.

For each pair, you should either assign an opening bracket to both elements, or closing bracket to both elements. You need to make the resulting sequence of brackets a correct bracket sequence or determine that it is impossible. If there are several possible solutions, find the solution with the smallest lexicographically string (of 2ドルn$ brackets, '(' is smaller than ')').

입력

The first line contains one integer $n$ (1ドル \leq n \leq 200,000円$).

The next line contains 2ドルn$ integers, $p_1, p_2, \ldots, p_{2n}$ (1ドル \leq p_i \leq n$). All integers from 1ドル$ to $n$ appear exactly two times in this sequence.

출력

If it is impossible to choose one type of bracket for each pair to make the derived bracket sequence correct, print "(" (Russian sad smiley). Otherwise, print the desired lexicographically minimal correct bracket sequence.

제한

예제 입력 1

2
1 2 1 2

예제 출력 1

()()

예제 입력 2

1
1 1

예제 출력 2

(

예제 입력 3

4
4 3 1 2 3 2 1 4

예제 출력 3

(

예제 입력 4

4
3 1 2 1 4 3 2 4

예제 출력 4

(()()())

예제 입력 5

4
2 4 3 1 3 4 2 1

예제 출력 5

()()()()

예제 입력 6

4
4 4 3 3 1 2 1 2

예제 출력 6

(((())))

예제 입력 7

4
1 3 1 2 4 4 2 3

예제 출력 7

()(())()

힌트

출처

Contest > Open Cup > 2019/2020 Season > Stage 16: Grand Prix of Moscow B번

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

출처

대학교 대회

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

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