Game of Chairs
Time limit2sMemory limit512 MB
Choose a starting chair to minimize the expected distance to the nearest chair of a uniformly random color, and output the expectation as a reduced fraction.
- Level
Hard8 of 10
- Topics
- Math, Prefix sum, Brute force, Implementation
- Solved
- No attempts yet
Problem
You are participating in a strange game. There are chairs in a row at a distance of one meter from each other. Each chair is painted by one of different colors.
At the beginning, you can sit on any chair. Then the jury will choose a color and announce it. Each color has probability to be chosen. Your task is to move to any chair of this color.
Of course, you will move to the nearest appropriate chair. If you are already sitting on it, you will not move at all.
You want to pick a chair to sit at the beginning to minimize the expected distance which you will have to walk.
Input
In the first line there are two integers and : the number of chairs and the number of colors ().
The second line contains integers : the colors of chairs (). There is at least one chair of each color.
Output
Output the expected distance as an irreducible fraction.