Решаю задачу
https://informatics.mccme.ru/moodle/mod/statements...
Не проходит по времени выполнения. Вот мое решение:
def get_data():
f = open('input.txt', 'r')
text = f.read()
f.close()
_count_of_people, _count_of_actions, _actions = process_data(text)
_queue = get_init_queue(_count_of_people)
return _count_of_people, _count_of_actions, _actions, _queue
def process_data(text):
data = text.split()
_count_of_people = int(data[0])
_count_of_actions = int(data[1])
_actions = data[2:]
return _count_of_people, _count_of_actions, _actions
def get_init_queue(_count_of_people):
_queue = list()
for i in range(1, _count_of_people + 1):
_queue.append(str(i))
return _queue
def get_answer(_count_of_actions, _actions, _queue):
for i in range(_count_of_actions):
action = actions[i]
index = _queue.index(action)
_queue.pop(index)
_queue.append(action)
return _queue
def set_answer(_queue):
f = open('output.txt', 'w')
text = ' '.join(_queue)
f.write(text)
f.close()
count_of_people, count_of_actions, actions, queue = get_data()
answer = get_answer(count_of_actions, actions, queue)
set_answer(answer)
Какие будут советы по алгоритму?