Сайт Каттис:
https://open.kattis.com/contests/en6o4k ... ftandright
Альтернативная форма просмотра:
Левый и правый конкурсный вопрос.
Я не совсем понимаю быстрый ввод для Python, поэтому я также был бы признателен, если бы кто-нибудь объяснил, возможно, это могло бы помочь. с время выполнения.
Вот код, который я разработал для решения этого вопроса:
Код: Выделить всё
# My method is to:
# 1. group blocks of the initial Left Right sequence
# 2. loop through the groups list to get the sequence
n = int(input())
word = input()+"a" # adding in "a" for the grouping algorithm
groups = [] # list for grouping string by blocks of "R" and "L"
seq = [] # final sequence the robot moves
pos = 1 if word[0] == "R" else 0 # position will always start with 1 if the robot is moving right first
if pos == 1:
seq = [1]
# grouping algorithm
group = word[0]
for i in word[1:]:
if i==group[0]:
group+=i
else:
groups.append(group)
group=i
# sequence algorithm
for c, i in enumerate(groups):
if "R" in i:
for j in i[:-1]:
pos+=1
seq.append(pos)
if c+1 == len(groups):
seq.append(pos+1)
else:
pos+=len(i)+1
seq.append(pos)
for k in range(len(i)):
seq.append(pos-1-k)
print(*seq, sep ="\n")
Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/792 ... tle-kattis
Мобильная версия