Naming the Computer
Time limit2sMemory limit512 MB
Given a string S and integer K, find the shortest string that contains S as a substring at least K times, and output its length.
- Level
Hard8 of 10
- Topics
- String matching, Dynamic programming, String, Greedy
- Solved
- No attempts yet
Problem
Ukje is naming the computer he just bought.
The name of the new computer must contain , Ukje's favorite string, as a substring at least times. If several names are possible, the name must have the shortest length.
Given and , find the length of the name of Ukje's new computer.
Input
The first line gives and . consists only of lowercase English letters and has length at most 500,000. is a positive integer at most 1,000,000.
Output
Print the length of the name of Ukje's new computer on the first line.