EPS/2024/04/15-04-24/e.py

46 lines
1.0 KiB
Python
Raw Normal View History

2024-04-29 13:33:02 +02:00
N = int(input())
customers = [int(i) for i in input().split()]
results = [0 for _ in range(N+1)]
# contient num. cust suivi de:
# 0: jsp
# 1: forcément G
# 2: forcément S
stack = [] # alt, vu
def depop(action):
seen = False
for i, (el, se) in enumerate(reversed(stack)):
if el == action:
del stack[len(stack)-i-1]
if se and seen:
raise ValueError
elif se:
return 1 # G
elif seen:
return 2 # S
return 1 # G
stack[len(stack)-i-1] = (el, True)
seen = True
def load_results():
for action in customers:
#print(action, stack)
if action > 0:
stack.append((abs(action), False))
else:
results[abs(action)] = depop(abs(action))
try:
load_results()
for i in results[1:]:
if i==0:
print("U", end="") # Unknown
elif i==1:
print("G", end="")
else:
print("S", end="")
print()
except ValueError:
print("*")