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

25001번 - Pen 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB112443948.750%

문제

Johnny loves order and is very upset by untidy parentheses. Lately he saw a string "){([]", which annoyed him since it was not a correct bracket sequence. Fortunately, Johnny had a pen in his pocket and he could add '(' at the beginning and ')}' at the end. Then he could sleep soundly again, since the string "(){([])}" is a correct bracket sequence.

Johnny took on repairing bracket sequences to be his life's mission. He will do this by adding new parentheses at the beginning and at the end of sequences he finds, so as to make them correct. Since his pen is running out of ink, Johnny would like to add the least possible number of brackets which will accomplish this. Help him! Write a program which will read a bracket sequence and either compute a shortest possible corrected bracket sequence for it and write it to standard output, or say that there is no way to correct it.

Correct bracket sequences are defined recursively as follows:

  • the empty sequence is a correct bracket sequence,
  • if $S$ and $T$ are correct bracket sequences, then their concatenation $ST$ is also a correct bracket sequence,
  • if $S$ is a correct bracket sequence, then $(S),ドル $[S]$ and $\{S\}$ are all also correct bracket sequences.

입력

The first and only line of input contains a nonempty sequence consisting of characters (, ), [, ], {, } and having length at most 1ドル,000円,000円$; this is the bracket sequence that Johnny wants corrected.

출력

The output should contain a corrected input sequence. If there are many possible ways to correct the input sequence that have the same minimum length, output any of them.

If it is impossible to correct the input sequence, output the word NIE.

제한

예제 입력 1

){([]

예제 출력 1

(){([])}

예제 입력 2

([]}

예제 출력 2

NIE

힌트

First example is the one from the problem statement.

In the second example, sequence cannot be repaired.

출처

ICPC > Regionals > Europe > Central European Regional Contest > Poland Collegiate Programming Contest > AMPPZ 2015 F번

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

출처

대학교 대회

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

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