#4641. Chinese Restaurant (Three-Star Version)
Chinese Restaurant (Three-Star Version)
Chinese Restaurant (Three-Star Version)
题目描述
Person , Person , , and Person are sitting around a turntable in counterclockwise order, evenly spaced. Dish is in front of Person on the table.
You may perform the following operation or more times:
Rotate the turntable by one -th of a counterclockwise turn. The dish that was in front of Person right before the rotation is now in front of Person .
When you are finished, Person gains frustration of , where is the minimum integer such that Dish is in front of either Person or Person .
Find the minimum possible sum of frustration of the people.
What is $a \bmod m$?
For an integer $a$ and a positive integer $m$, $a \bmod m$ denotes the integer $x$ between $0$ and $(m-1)$ (inclusive) such that $(a-x)$ is a multiple of $m$. (It can be proved that such $x$ is unique.)输入格式
Input is given from Standard Input in the following format:
输出格式
Print the answer.
4
1 2 0 3
2
3
0 1 2
0
10
3 9 6 1 7 2 8 0 5 4
20
提示
if .
All values in input are integers.下面的图展示了一次操作之后的桌面情况。
在这里,他们的沮丧总和为 ,因为:
Person gains a frustration of since Dish is in front of Person ; Person gains a frustration of since Dish is in front of Person ; Person gains a frustration of since Dish is in front of Person ; Person gains a frustration of since Dish is in front of Person .
We cannot make the sum of their frustration less than , so the answer is .
标签: AtCoder|abc268E
来源
AtCoder|abc268E