Non-Interactive Guessing Number
Time limit2sMemory limit512 MB
Given N, K, and Theodora's answer string, output guess values that follow the rules, or -1 if impossible.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Math, Implementation
- Solved
- No attempts yet
Problem
Romanos: “Can I submit an interactive problem to the contest?”
Theodora: “No.”
Romanos: “Aww, that is not fun.”
So Romanos submitted this non-interactive version instead. Theodora first chooses an integer between and inclusive. Romanos may make up to guesses. For each guess, Theodora answers if her number is smaller than the guess, if her number is larger than the guess, and if the guess is correct. The game ends immediately when Romanos guesses correctly, or after wrong guesses.
Romanos does not always play optimally, but he never makes a silly guess. Every guess lies between and inclusive and is consistent with all previous answers. For example, if and his first guess is and the answer is , his next guess is always between and inclusive.
Theodora plays to make Romanos lose and changes her hidden number adaptively whenever it stays consistent with her previous answers. Whenever she can answer or , she chooses the answer that leaves the larger set of possible numbers. If both sides leave the same number of possibilities, she answers . For example, if and the first guess is , she answers because to inclusive is larger than to inclusive.
You are given , , and the sequence of Theodora's answers. Output any guess sequence by Romanos that is consistent with the rules of both players, or if no such sequence exists.
Input
The first line contains two integers and (, ), the range of numbers and the maximum number of guesses.
The second line contains a string of Theodora's answers. Each character is one of , , , and either:
- the last character is , every other character is or , and the length of is at most , or
- every character is or , and the length of is exactly .
Output
Let be the length of .
- If a guess sequence consistent with the rules exists, output integers in one line, where is the -th guess. If several sequences exist, output any of them.
- Otherwise output in one line.