AlgoLensArena
ContestlərProblemlərOtaqlar
Vizualizator
← Məsələlər

BAPC24-065.Karaoke Compression

Medium · 5 s · 256 MB

  • icpc
  • bapc
  • 2024

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 sss be the string to compress. You select exactly one nonempty substring ttt of the lyrics, and replace as many occurrences of ttt in sss as possible by a new character that did not occur in sss before. Call the result of this s′s's′. Now you only need to remember the substring ttt and the compressed string s′s'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=162 + 14 = 162+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=144 + 10 = 144+10=14, which is optimal.

Giriş formatı

The input consists of:

• One line with a string sss (1≤∣s∣≤5000)(1 \leq |s| \leq 5000)(1≤∣s∣≤5000), the lyrics to compress.

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

Çıxış formatı

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

Qeyd

Source: Benelux Algorithm Programming Contest 2024 · Author: Jorke de Vlas · License: CC BY-SA 4.0 · Original: https://bapc.eu · Statement adapted for AlgoLens and shared under the same license. · 28 of the 148 original test cases (the largest) are omitted here to keep the problem lightweight.

Nümunələr

Giriş #1

nanananananananabatman

Çıxış #1

14

Giriş #2

abcabd

Çıxış #2

6

Giriş #3

nocompression

Çıxış #3

14