#P10349. [PA 2024] Mrówki
[PA 2024] Mrówki
Problem Description
This problem is translated from PA 2024 Practice Round Mrówki.
There are ants on the number line. Ant is located at the point . Each ant is facing either to the right (the positive direction of the number line) or to the left (the opposite of the positive direction). The ants are so small that we can treat them as independent points.
After the signal is given, all ants start moving at the same unit speed in the direction they are facing. If two ants collide (they are at the same point), they bounce off, meaning both of them change their moving direction and continue moving. It can be proven that after some time, no more collisions will happen. Write a program to compute how many times each ant will collide with other ants.
Input Format
The first line contains an integer , representing the number of ants.
The second line contains a string of length , consisting only of L and P. The -th character describes the direction of ant : if it is L, it initially faces left; if it is P, it initially faces right.
Output Format
Output one line with integers. The -th integer should be the number of collisions between ant and other ants.
6
LPPLPL
0 1 3 3 2 1
Hint
The first ant initially faces left, so it will not collide with any other ant. The last ant will collide with the fifth ant at , then start moving to the right, and it will never stop again. The third ant will collide with the fourth ant at , then start walking to the left. The second ant will collide at , then turn left, and keep going forever after that.
Translated by ChatGPT 5