#P17135. [KOI 2026 #1] 剪刀石头布
[KOI 2026 #1] 剪刀石头布
Problem Description
There are people numbered from to standing in a line. For each integer (), person stands at the -th position from left to right and holds a card . Each card is one of Scissors (S), Rock (R), or Paper (P).
Two different people are called adjacent if there is no one between them. You may choose two adjacent people and let them play a duel. Each duel is carried out as follows:
- If the two people hold different cards, the winner is determined by the rules of rock-paper-scissors. Specifically, Rock (R) beats Scissors (S), Scissors (S) beats Paper (P), and Paper (P) beats Rock (R).
- If the two people hold the same card, you may choose either one to be the winner.
The loser leaves the line. The winner keeps their original card and stays at their original position. After someone leaves, two people who were not adjacent may become adjacent, and they can duel later.
You must perform exactly duels so that only one winner remains in the end. Write a program to determine, for each person, whether there exists an arrangement of duels that allows them to become the final winner.
Input Format
The first line contains an integer .
The second line contains a string of length . The -th character of indicates the card held by person , and is one of the uppercase letters S, R, P ().
Output Format
Output a string of length on the first line. For each , the -th character should be: if person can become the final winner; otherwise ().
3
RPP
011
3
RPS
101
Hint
Sample Explanation 1
If person duels person first, since they hold the same card, you may choose the winner. If you choose person to win, then the remaining person and person will duel. Since Paper (P) beats Rock (R), person can become the final winner.
You can also let person duel person and choose person to win, then let person duel person . In this way, person can become the final winner.
Since Rock (R) cannot beat Paper (P), person can never become the final winner.
Sample Explanation 2
If person duels person first, since Scissors (S) beats Paper (P), person wins. When the remaining person duels person , since Rock (R) beats Scissors (S), person can become the final winner.
If person duels person first, since Paper (P) beats Rock (R), person wins. When the remaining person duels person , since Scissors (S) beats Paper (P), person can become the final winner. Person can never become the final winner.
Constraints
.
is a string of length and consists only of the uppercase letters S, R, P.
Subtasks
- (13 points) .
- (16 points) The string contains at most two different characters.
- (47 points) .
- (31 points) .
- (43 points) No additional constraints.
Translated by ChatGPT-5.6.
Translated by ChatGPT 5