#abc268e. E - Chinese Restaurant (Three-Star Version)
E - Chinese Restaurant (Three-Star Version)
Score : points
问题描述
设有0号、1号、以及(N-1)号人士,他们按照逆时针方向均匀地围绕在一个转盘周围。第道菜位于第i号人士面前的桌子上。
你可以执行以下操作零次或多次:
- 将转盘逆时针旋转 圈。在旋转前位于第i号人士面前的那道菜现在会出现在第 号人士面前。
完成所有操作后,第i号人士会增加 点沮丧值,其中是最小整数,使得第i号菜此时位于第 号或第 号人士面前。
求最终这N位人士沮丧值之和的最小可能值。
什么是?对于一个整数和一个正整数,表示的是在到(包含两端点)之间的一个整数,满足是的倍数。(可以证明这样的是唯一的。)
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
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 ? For an integer and a positive integer , denotes the integer between and (inclusive) such that is a multiple of . (It can be proved that such is unique.)
Constraints
- if .
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4
1 2 0 3
Sample Output 1
2
The figure below shows the table after one operation.
Here, the sum of their frustration is because:
- 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 .
Sample Input 2
3
0 1 2
Sample Output 2
0
Sample Input 3
10
3 9 6 1 7 2 8 0 5 4
Sample Output 3
20
update @ 2024/3/10 11:18:43