Logo
(追記) (追記ここまで)

31755번 - Expanding STACKS! 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB76363559.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:

  • There is a single line inside the restaurant.
  • When a customer enters, they immediately join the back of the line.
  • Whenever a stack of glazed pancakes (the only dish at STACKS!) is ready, it’s served to the person at the back of the line, who then immediately devours the pancakes and leaves the restaurant.

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:

  • There are two lines, one for each type of pancake. Each customer joins the back of the line corresponding to the type of pancake they want.
  • Whenever a stack of glazed pancakes is ready, it is served to the customer at the back of the glazed pancake line, who immediately devours it and leaves the restaurant.
  • Whenever a stack of savory pancakes is ready, it is served to the customer at the back of the savory pancake line, who instantly gobbles it and leaves the restaurant.

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.

제한

예제 입력 1

2
+2 +1 -1 -2

예제 출력 1

GG

예제 입력 2

2
+1 +2 -1 -2

예제 출력 2

GS

예제 입력 3

2
+1 +2 -1 -2

예제 출력 3

SG

예제 입력 4

3
+1 +2 +3 -1 -2 -3

예제 출력 4

*

힌트

출처

ICPC > Regionals > Latin America > Latin America Championship > The 2024 ICPC Latin America Championship E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /