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

19811번 - Too Many Hyphens 다국어

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

문제

Document markup languages such as TeX and LaTeX, originally developed by Donald Knuth and Leslie Lamport, are often used in typesetting various articles, scientific texts, and even the statements for programming olympiads.

They provide special macros which allow one to use special characters that aren't present on the keyboard. For example, several hyphens in a row are converted into dashes of various lengths. Thus, when it's necessary to get a line of several hyphens in a document, you need to make some special actions.

In this case one can use braces to prevent a group of successive hyphens to be a macro. As in many programming languages (C++, for example) braces are used in TeX to group character blocks. Braces sequence should also form a correct parentheses sequence. That means that after removing all the characters from the line except braces, and then replacing the opening brace "{" with $+1$ and closing brace "}" with $-1,ドル the sum of all the elements of the resulting sequence should be equal to 0ドル,ドル and the sum of any prefix of the resulting sequence should be non-negative.

To prevent the sequence of hyphens from being replaced by a dash there should be at least one brace between any two consecutive hyphens. Note that the group of consecutive pluses, unlike hyphens, does not correspond to any macro and thus there are no extra conditions for two consecutive pluses.

Let's consider the string $s$ consisting of pluses and hyphens. Let's add the minimum number of curly braces considering the rules described above, so that there are no two consecutive hyphens. Let's call the resulting string an optimal escaped string for $s$.

For example, for the string "++-{-}" there are exactly five optimal escaped strings: "++-{-}", "++-{-}", "++{--}", "+{+--}", "{++--}".

The lines above are listed in lexicographical order: they are ordered by the first unequal character (by the first, then by the second in case the first characters are equal, etc). Characters are ordered as "+"$\strut<\strut$"-"$\strut<\strut$"{"$\strut<\strut$"}".

Let's consider all the minimal length strings that can be obtained from $s$ by adding bracers by the described rules, namely all optimal escaped strings for $s$. You must find the $k$-th in lexicographical order optimal escaped string or detect that the given $k$ is too great.

입력

The first line of input contains the string $s,ドル consisting of pluses and hyphens. It's guaranteed that $s$ is not empty and has a length of no more than 60ドル$ characters.

The second line contains a single integer $k$ (1ドル \le k \le 10^{18}$).

출력

You need to print the $k$-th in lexicographical order optimal escaped string for the string $s$ specified in the input.

If $k$ is greater than the number of optimal escaped strings, your program should print "Overflow".

제한

예제 입력 1

++--
2

예제 출력 1

++-{}-

예제 입력 2

-+-+-
2

예제 출력 2

Overflow

힌트

출처

Olympiad > Russian Olympiad in Informatics > Russia Team High School Programming Contest > Russia Team High School Programming Contest 2019 G번

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

출처

대학교 대회

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

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