Non-Repeating Word
Time limit2sMemory limit128 MB
Find the lexicographically smallest length-N string over the first A letters that never contains K consecutive copies of any nonempty block.
- Level
Hard8 of 10
- Topics
- Backtracking, String, Greedy, Brute force
- Solved
- No attempts yet
Problem
A positive integer K is given. A string S is called K-repeat-free if there is no nonempty string T such that T repeated K consecutive times appears as a substring of S.
Given K, N, and A, find the lexicographically smallest word of length N that is K-repeat-free and uses only the first A uppercase English letters.
Input
The first line contains three integers K, N, and A.
Output
Print the required word. If no such word exists, print -1.
Constraints
- 2 <= K <= 10
- 1 <= N <= 50
- 1 <= A <= 26