포럼
문제 ICPC00364

K. Karaoke Compression

설명

Next week, you will be hosting the Biannual Acoustic Popsong Convention. Of course, this convention also needs to include a karaoke night, featuring all your favourite acoustic pop songs! To impress all attendees, you have decided to prepare by learning the lyrics of all the songs by heart. But there is a problem: these lyrics are very long, so you will not have enough time left to learn all of this! However, you have noticed that a lot of the songs contain quite some repetitions. This gives you the idea of first compressing the lyrics, and then only learning the compressed version.

The compression scheme you will use works as follows. Let \(s\) be the string to compress. You select exactly one nonempty substring \(t\) of the lyrics, and replace as many occurrences of \(t\) in \(s\) as possible by a new character that did not occur in \(s\) before. Call the result of this \(s'\). Now you only need to remember the substring \(t\) and the compressed string \(s'\). You would like to know the minimal total length of these two strings, if you compress the lyrics in this manner.

As an example, consider the first sample case. In this case, you want to compress the lyrics "nanananananananabatman". If you replace the substring "na" by the character "X", the compressed string becomes "XXXXXXXXbatman". The total length of the substring and compressed string in this case is \(2 + 14 = 16\). However, if you instead choose to replace the substring "nana", then the compressed string is "XXXXbatman" and the total length is \(4 + 10 = 14\), which is optimal.

제약
입력 형식

The input consists of:
- One line with a string \(s\) \((1 \leq |s| \leq 5000)\), the lyrics to compress.

The string only consists of English lowercase letters (a-z).

출력 형식

Output the minimal total length of the replaced substring and the compressed string.

예제 1
입력
nanananananananabatman
출력
14
예제 2
입력
abcabd
출력
6
예제 3
입력
nocompression
출력
14
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC BAPC 2024

평가 및 의견

K. Karaoke Compression

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

K. Karaoke Compression

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8