| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 1 초 (추가 시간 없음) | 1024 MB | 76 | 36 | 35 | 59.322% |
Tired of always waiting in lines, you invented a revolutionary restaurant concept: “STACKS! Where the last customer is served first”.
The restaurant operates as follows:
This business model has been incredibly successful, so much so that STACKS! is beginning to expand.
In fact, you just opened the very first STACKS!+, offering two types of pancakes: glazed and savory. The new restaurant works as follows:
As the boss, you want to ensure your employees follow the concept and maintain your vision. Given the order in which customers come in and out of the restaurant, you need to determine whether there is an assignment of customers to lines such that the STACKS!+ concept is followed.
You can assume that whenever a customer enters the restaurant, they immediately join the back of a line, and that they leave as soon as they are served. Also, each customer visits the restaurant exactly once.
The first line contains an integer $N$ (1ドル ≤ N ≤ 1000$) indicating the number of customers who visited STACKS!+. Each customer is identified by a distinct integer from 1ドル$ to $N$.
The second line contains 2ドルN$ signed integers $X_1, X_2, \dots , X_{2N}$ (1ドル ≤ |X_i | ≤ N$ for $i = 1, 2, \dots , 2N$) indicating, in chronological order, the entrance and departure of the customers. The value $X_i = +c$ denotes the entrance of customer $c$ into the restaurant, while $X_i = -c$ represents their departure. It is guaranteed that each customer enters and leaves the restaurant exactly once, and that they do not leave before entering.
Output a single line with a string of length $N$ if there is an assignment of customers to lines such that the STACKS!+ concept can be honored. In this case the $i$-th character of the string must be the uppercase letter “G” if customer $i$ is assigned to the glazed pancake line, and the uppercase letter “S” if they are assigned to the savory line. If there are multiple solutions, output any of them.
If the STACKS!+ concept cannot be honored with the given input, output the character “*” (asterisk) instead.
2 +2 +1 -1 -2
GG
2 +1 +2 -1 -2
GS
2 +1 +2 -1 -2
SG
3 +1 +2 +3 -1 -2 -3
*