Binary Search Game
Time limit2sMemory limit64 MB
Determine whether a player can always guess x within a_x comparison questions given a monotone budget array, and list all valid first questions q.
- Level
Hard8 of 10
- Topics
- Binary search, Greedy, Dynamic programming
- Solved
- No attempts yet
Problem
Jihak built the following game to teach binary search.
- The computer picks an integer at random with and tells the player the value of .
- The player picks an integer and asks "Is at most ?". The computer answers yes or no. The player may ask this question as often as they want, and there is no restriction on the integer .
- Once the player decides that is known, the player names a guess and asks "Is equal to ?" one time. The computer prints the verdict and the game ends.
Students were learning binary search from this game until Jaehyun told them the optimal strategy in advance, which made the game too easy. Jihak then changed the rule. The computer prints success only when and the number of "Is at most ?" questions asked so far is at most , and prints failure otherwise. The final confirmation question is not counted. Jihak likes sorted sequences, so the sequence satisfies .
Jaehyun could not find a way to always succeed in the changed game and claimed that no such way exists. Jihak could not prove otherwise and asked you for help.
Decide whether there is a way of asking that always succeeds no matter which the computer picked, and if there is, find every that may be asked as the first question. A value may be asked as the first question when there is a way to start with "Is at most ?", then choose every later question from the answers received, and succeed for every .
Input
The first line contains ().
The second line contains integers () separated by spaces.
Output
On the first line, print how many values of may be asked as the first question. If infinitely many such exist, print inf instead of a count.
On the second line, print those values of in increasing order, separated by spaces. If no such exists, or if infinitely many exist, print nothing on the second line.