#P8048. [COCI 2015/2016 #4] ENDOR
[COCI 2015/2016 #4] ENDOR
Problem Description
If we believe the Guinness World Records, on the forest-covered moon of Endor there is the longest stick in the entire galaxy. On this stick of length meters, there are cheerful chameleons. Each chameleon moves along the stick at a constant speed of meter per second in one of two possible directions (left or right), and is colored in one of possible colors.
As everyone knows, the chameleons on Endor worship the ancient ant rule, which says that a chameleon must keep walking along the stick until it reaches an end of the stick, and when it collides with another chameleon, it must turn degrees and continue walking in the opposite direction. In addition, after a collision between a left-moving chameleon with color and a right-moving chameleon with color , the chameleon that was moving left before the collision takes the color of the chameleon that was moving right before the collision, while the chameleon that was moving right before the collision takes the new color .
Given the initial position, color, and moving direction of every chameleon, for each color, determine the total distance traveled by chameleons of that color before they leave the stick.
Input Format
The first line contains three integers , representing the number of chameleons, the number of colors, and the length of the stick.
Then follow lines. Each line contains two integers and a character L or D, where are the distance of the -th chameleon from the left end of the stick and its color, respectively. If the character is L, it means the -th chameleon initially faces left; otherwise, it initially faces right. It is guaranteed that all are distinct and are given in increasing order.
Output Format
Output lines. The -th line should output a real number, representing the total distance traveled before leaving the stick by chameleons that have color , rounded to one decimal place. It can be proven that the answer is either an integer or a one-decimal number of the form .
2 3 10
0 0 D
10 1 L
10.0
10.0
0.0
4 3 7
1 0 D
3 0 D
4 1 L
6 2 D
10.0
4.0
1.0
4 4 5
1 1 D
3 3 L
4 2 D
5 0 L
2.5
4.0
2.5
4.0
Hint
[Sample 1 Explanation]
The two chameleons collide after walking meters. After that, chameleon changes its color to , and chameleon changes its color to . Then each of them continues walking another meters and leaves the stick. Therefore, chameleons of color and color each travel a total of meters, and there are no chameleons of color during this process.
[Constraints]
For of the testdata, .
For all testdata, , , , , , .
[Source]
This problem is from COCI 2015-2016 CONTEST 4 T6 ENDOR, using the original testdata configuration, with a full score of points.
Translated and organized by Eason_AC.
Translated by ChatGPT 5