ENG  RUS Timus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

## Обсуждение задачи 1330. Интервалы

Optimizing Python code
Послано LearningPython 18 сен 2013 01:15
Hello

My python code is as follows:

[code deleted]

I get TLE in # 20
Where can I save time?

Edited by moderator 01.12.2019 21:35
Re: Optimizing Python code
Послано Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 18 сен 2013 03:36
I'm not sure, but maybe a lot of .append()'s could work too slow...
Maybe you could try a = [0] * n and then a[i] = ...
Re: Optimizing Python code
Послано Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 18 сен 2013 04:29
Tough to AC, but possible (finally I managed to do it).
Since there can be up to 100000 queries, bottleneck is output as usual with Python.
Don't use print - use sys.stdout.write() instead (interestingly, why you used sys.stdin for input and print for output?)

Edited by author 18.09.2013 04:30
Re: Optimizing Python code
Послано LearningPython 20 сен 2013 22:39
Hello

When I change my solution with a=[0]*n it takes 0.546 sec
Before the change it took 0.515 sec.

The first hint brings no AC

Edited by author 20.09.2013 22:41

Edited by author 20.09.2013 22:41
Re: Optimizing Python code
Послано LearningPython 20 сен 2013 22:53
Using sys.stdout.write ('\n'.join ([str (x) for x in b])

My solution takes .515 sec

No AC
Re: Optimizing Python code
Послано Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 20 сен 2013 22:58
Looking at TLE times in testing queue is a misleading way to analyze your code effectiveness (actually, it shows time after which your code was halted with TLE verdict rather than acrtual running time). Test it locally on large tests and measure time efficiency of each alternative.
Also, I see you submit on Python 3. That may be the problem - I ACed on Python 2.
Re: Optimizing Python code
Послано LearningPython 21 сен 2013 03:57
I used python 2.7.5 this time.
My code was unchanged
AC in .468