#P17135. [KOI 2026 #1] 剪刀石头布

    ID: 19478 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>贪心前缀和2026KOI(韩国)

[KOI 2026 #1] 剪刀石头布

Problem Description

There are NN people numbered from 11 to NN standing in a line. For each integer ii (1≤i≤N1 \le i \le N), person ii stands at the ii-th position from left to right and holds a card AiA_i. 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 N−1N-1 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 NN.

The second line contains a string AA of length NN. The ii-th character AiA_i of AA indicates the card held by person ii, and is one of the uppercase letters S, R, P (1≤i≤N1 \le i \le N).

Output Format

Output a string of length NN on the first line. For each ii, the ii-th character should be: 11 if person ii can become the final winner; otherwise 00 (1≤i≤N1 \le i \le N).

3
RPP
011
3
RPS
101

Hint

Sample Explanation 1

If person 22 duels person 33 first, since they hold the same card, you may choose the winner. If you choose person 22 to win, then the remaining person 11 and person 22 will duel. Since Paper (P) beats Rock (R), person 22 can become the final winner.

You can also let person 22 duel person 33 and choose person 33 to win, then let person 33 duel person 11. In this way, person 33 can become the final winner.

Since Rock (R) cannot beat Paper (P), person 11 can never become the final winner.

Sample Explanation 2

If person 22 duels person 33 first, since Scissors (S) beats Paper (P), person 33 wins. When the remaining person 11 duels person 33, since Rock (R) beats Scissors (S), person 11 can become the final winner.

If person 11 duels person 22 first, since Paper (P) beats Rock (R), person 22 wins. When the remaining person 22 duels person 33, since Scissors (S) beats Paper (P), person 33 can become the final winner. Person 22 can never become the final winner.

Constraints

1≤N≤200 0001 \le N \le 200\,000.

AA is a string of length NN and consists only of the uppercase letters S, R, P.

Subtasks

  1. (13 points) N≤3N \le 3.
  2. (16 points) The string AA contains at most two different characters.
  3. (47 points) N≤100N \le 100.
  4. (31 points) N≤5 000N \le 5\,000.
  5. (43 points) No additional constraints.

Translated by ChatGPT-5.6.

Translated by ChatGPT 5