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

30931번 - Nested Repetition Compression 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 (추가 시간 없음) 1024 MB87575465.854%

문제

You have a number of strings of lowercase letters to be sent in e-mails, but some of them are so long that typing as they are would be tiresome. As you found repeated parts in them, you have decided to try out a simple compression method in which repeated sequences are enclosed in parentheses, prefixed with digits meaning the numbers of repetitions. For example, the string “abababaaaaa” can be represented as “3(ab)5(a)” or “a3(ba)4(a)”. The syntax of compressed representations is given below in Backus-Naur form with the start symbol $S$.

<$S$> ::= <$R$> | <$R$> <$S$>

<$R$> ::= <$L$> | <$D$> (<$S$>)

<$D$> ::= 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9

<$L$> ::= a | b | c | d | e | f | g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v | w | x | y | z

Note that numbers of repetitions are specified by a single digit, and thus at most nine, but more repetitions can be specified by nesting them. A string of thirty a’s can be represented as “6(5(a))” or “3(5(2(a)))”, for example.

Find the shortest possible representation of the given string in this compression scheme.

입력

The input is a line containing a string of lowercase letters. The number of letters in the string is at least one and at most 200ドル$.

출력

Output a single line containing the shortest possible representation of the input string. If there exist two or more shortest representations, any of them is acceptable.

제한

예제 입력 1

abababaaaaa

예제 출력 1

3(ab)5(a)

예제 입력 2

abababcaaaaaabababcaaaaa

예제 출력 2

2(3(ab)c5(a))

예제 입력 3

abcdefg

예제 출력 3

abcdefg

힌트

출처

ICPC > Regionals > Asia Pacific > Japan > ICPC 2023 Asia Yokohama Regional D번

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

출처

대학교 대회

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

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