#P12543. [APIO2025] Rotating Lines
[APIO2025] Rotating Lines
题目描述
Asadullo is an outstanding researcher at APIO (Alliance for Power and Industrial Optimization). Recently, he has been studying a method to generate energy using an unknown material.
This unknown material does not produce energy on its own, but if there are several extremely long rods made of this material, they can generate energy through their interactions.
Specifically, there are rods, given by an array . The -th rod can be positioned at an angle of , with respect to the positive direction of the x-axis, in counterclockwise. The energy efficiency by these rods is defined as
where represents the acute angle formed between the -th rod and the -th rod. In this problem, we consider as an acute angle.
More formally, $\text{acute}(i,j) = \min(|v[i] - v[j]|, 50000 - |v[i] - v[j]|)$.
In other words, the energy efficiency is calculated by adding the acute angles between every pair of rods.
For example, if and correspondingly, , we would get the following graph:
Here, acute(0, 1) = 7500 (i.e. 27°), acute(0, 2) = 17500 (i.e. 63°), and acute(1, 2) = 25000 (i.e. 90°). Therefore, the energy efficiency of these rods equals .
Asadullo wants to adjust the arrangement of these rods to maximize their energy efficiency. However, there are several constraints:
- First, since this material is extremely hazardous to living beings, the rods can only be rotated using a specialized mechanical device in a controlled manner. This device allows selecting multiple rods at once and rotating them by the same angle simultaneously.
- Asadullo does not want the energy efficiency of the rods to decrease. Therefore, after any operation using the device, the energy efficiency must not be lower than before.
- Since operating the device consumes a large amount of energy, the total number of rods selected across all operations must not exceed 2 000 000.
Under these constraints, Asadullo wants to perform operations optimally to maximize the energy efficiency of the rods. Write a program to help Asadullo achieve the highest possible energy efficiency.
Implementation details
You should implement the following procedure:
void energy(int n, std::vector<int> v)
- : the number of rods.
- : an array of length containing information about the rods.
- This procedure is called exactly once.
Within this procedure, you may call the following procedure:
void rotate(std::vector<int> t, int x)
- : an array of distinct indices, i.e. for each and for each . Array is not required to be sorted.
- This procedure rotates every rod which index is given in the array by parameter , simultaneously. That is, becomes for every index which is present in .
- This procedure can be called multiple times. The total length of over all calls must not exceed 2 000 000.
提示
Examples
Example 1
Consider the following call:
energy(2, [20000, 10000])
Here, and the initial energy efficiency equals . One of the possible scenarios is the following:
- call
rotate([0, 1], 8000)
. Then becomes . The energy efficiency stays the same. - call
rotate([0], 15000)
. Then becomes . The energy efficiency becomes .
It can be shown that for the given input, 25000 is the maximum possible energy efficiency. Therefore, Asadullo can stop performing these operations.
Example 2
Consider the following call:
energy(3, [5000, 12500, 37500])
The image for this example was presented above. It can be shown that the initial energy efficiency is the maximum possible. Thus, no operations are needed.
Constraints
- for each
- elements of are not necessarily distinct
Subtasks
- (5 points)
- (11 points) for each
- (8 points)
- (15 points)
- (15 points)
- (20 points)
- (26 points) No additional constraints.
Sample Grader
The sample grader reads the input in the following format:
- line 1:
- line 2:
The sample grader prints the output in the following format:
- line 1: final energy efficiency of rods
Also, the grader will write detailed information about the rotations you made in the file log.txt
.