#P7778. 『JROI-2』Dancing Line
『JROI-2』Dancing Line
Description
Note: This problem does not consider special turning methods such as “maze”, teleport lines such as “football”, or jumping and landing such as “piano”.
As everyone knows, the path in Dancing Line is a polyline. Each click will make the moving direction rotate clockwise or counterclockwise, and the rotation directions of any two adjacent rotations are different.
For example, the following are valid paths (the path does not have to follow the grid of the Cartesian coordinate system):


And the following are invalid paths:
The rotation angle is not :

Turning left twice in a row:

A path that obviously does not meet the requirements:

k Tian placed the path into a 2D coordinate system and wrote down the coordinates of the path’s start point, end point, and turning points (both coordinates are integers). He put them into a file and left.
When k Tian came back and turned on his computer, he found that all the data in his file was messed up. The coordinates of the points were no longer stored in the original order, but were arranged in a strange order.
k Tian wants to reconstruct the path from these data. He also wants to estimate the difficulty of this level, denoted by :
$$s=\sum\limits_{i=1}^{n}{t_i^2},t_i=\dfrac{d(P_{i-1},P_i)}{v}$$Where:
- denotes the -th point of the reconstructed path starting from the start point (the start point is , and the end point is ).
- is the line speed, a given positive integer.
- denotes the distance between points and in the coordinate system.
Can you help him?
Input Format
The first line contains two positive integers , with meanings as described above.
The next lines each contain two integers, representing the coordinates of each point in the file before reconstruction.
Output Format
Output one number as described above, and output its value modulo .
More specifically, suppose in lowest terms is . You need to output the smallest non-negative integer satisfying . In this problem, you should output .
8 2
-7 7
-11 5
-3 4
-5 3
4 0
0 -2
5 -2
13 2
15 -2
249561142
Hint
Explanation of the samples
For Sample 1, the path is as follows:

The lengths of the segments are $2\sqrt{5},2\sqrt{5},\sqrt{5},3\sqrt{5},2\sqrt{5},\sqrt{5},4\sqrt{5},2\sqrt{5}$. The value of is , and the result after taking modulo is .
Constraints and Notes
This problem uses bundled tests.
- Subtask 1 (5 pts): .
- Subtask 2 (15 pts): .
- Subtask 3 (30 pts): .
- Subtask 4 (50 pts): no special constraints.
For of the testdata, it holds that:
- .
- .
- .
- All point coordinates are guaranteed to be pairwise distinct.
- The given points are guaranteed to be able to reconstruct one and only one unique path.
, where .
Source: JROI-2 Summer Fun Round - T3
Idea&Sol&Data: kkk's little simp
Std&Retest: Tony2
Translated by ChatGPT 5
京公网安备 11011102002149号