#P10097. [ROIR 2023] 彩点 (Day 1)

[ROIR 2023] 彩点 (Day 1)

Background

Translated from ROIR 2023 D1T4

There are nn points on the plane, namely P1,P2,P3,,PnP_1,P_2,P_3,\dots,P_n。The coordinates of the ii-th point are (xi,yi)(x_i,y_i)

Choose two points Pi,PjP_i,P_j (iji\ne j)。Let PiP_i be the starting point and PjP_j be the ending point。With the ending point PjP_j as the center, starting from the direction of the vector PiPj\overrightarrow{P_iP_j}, sort all points except PjP_j in counterclockwise order (if angles are the same, sort by increasing distance to PjP_j)。Suppose the tt-th point in this order is PkP_k。Then repeat the operation: let PjP_j be the starting point and PkP_k be the ending point, reorder in the same way, and compute the index of the new ending point。This process repeats in a loop。

In the figure below, initially n=6,t=4,i=1,j=2n=6,t=4,i=1,j=2。Sort all points except P2P_2 in order, and the result is P3,P5,P1,P6,P4P_3,P_5,P_1,P_6,P_4,so the next ending point should be P6P_6,and the starting point is P2P_2

Now n=6,t=4,i=2,j=6n=6,t=4,i=2,j=6。Continue sorting by the rules. As in the lower-left figure, the result is P4,P3,P2,P1,P5P_4,P_3,P_2,P_1,P_5。So the next ending point is P1P_1,and the starting point is P6P_6

Now n=6,t=4,i=6,j=1n=6,t=4,i=6,j=1。Continue sorting by the rules. As in the upper-right figure, the result is P5,P6,P4,P2,P3P_5,P_6,P_4,P_2,P_3。So the next ending point is P2P_2,and the starting point is P1P_1。Now we return to the initial situation and enter a cycle。

Problem Description

We paint each of the nn points with one of three colors。The color of point ii is determined as follows:

  • If there exists a point jj such that, choosing point ii as the starting point and point jj as the ending point, in the process above point ii will become the starting point infinitely many times, then paint point ii green。
  • If point ii is not painted green and there exists a point jj such that, choosing point ii as the starting point and point jj as the ending point, in the process above point ii can still become the starting point at least once, then paint point ii blue。
  • If point ii is neither green nor blue, then paint point ii red。

For each point, determine which color it should be painted。

Input Format

The first line contains two integers nn and tt

The next nn lines each contain two integers xix_i and yiy_i。It is guaranteed that no two points coincide。

Output Format

Output one line containing nn characters。The ii-th character of the string indicates the color of the ii-th point。

Green points are denoted by the letter G,blue points by B,and red points by R

6 4
-1 -1
1 -2
4 -2
2 -4
2 3
-4 -5
GGBBRG
2 1
1 1
2 2
GG

Hint

Explanation for sample 11

In the example given above, we already know that P1,P2,P6P_1,P_2,P_6 form a cycle. These three points will definitely be visited infinitely many times, so they should be painted green。

When the starting point is P3P_3, we can take the ending point as P1P_1。After sorting, P3P_3 is exactly the fourth point, so P3P_3 returns to being a starting point again, as shown below. Therefore it should be painted blue。

When the starting point is P4P_4, we can choose P5P_5 as the ending point. After sorting, P4P_4 is exactly the fourth point. Therefore P4P_4 can be painted blue。When P5P_5 is the starting point, it is easy to see that it can be painted neither green nor blue, so it should be painted red。

This problem uses bundled testdata。

Subtask Score Special Properties
11 1010 n10n\le10,all points are collinear
22 1515 all points are collinear
33 1010 n10n\le10,there are no blue points
44 n10n\le10
55 1515 n100n\le100,there are no blue points
66 n100n\le100
77 55 n3n\ge3,all points form a strictly convex nn-gon, and are given in counterclockwise order
88 2020 none

Constraints for all data: $2 \le n \le 1 000, 1 \le t \le n−1, −10^9 \le x_i, y_i \le 10^9$。

Translated by ChatGPT 5