Alice and Bob (and string): Double Menace
Time limit2sMemory limit512 MB
Given string s and k, find the k-th lexicographically smallest substring t of s from which Alice wins the two-sided extension game, or report that fewer than k exist.
- Level
Hard9 of 10
- Topics
- Game theory, String matching, String
- Solved
- No attempts yet
Problem
Alice and Bob are playing a game. At the start they have a string and a substring of . On each turn, a player adds an arbitrary lowercase letter to the left of and an arbitrary lowercase letter to the right of , so that is still a substring of . A player who cannot make a valid move loses. Alice moves first.
Before her first move, Alice chooses the initial string . She wants a choice that guarantees her victory, assuming both players play optimally. To keep Bob from suspecting anything, she picks the -th lexicographically smallest of all winning initial strings. Help Alice.
Input
The first line contains the string of lowercase English letters ().
The second line contains the integer ().
Output
If there are fewer than winning initial strings, print "no solution". Otherwise, print the -th lexicographically smallest winning initial string. If that string is empty, print "-".
Hint
For , the winning strings are -, a, b, and ba.