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

Обсуждение задачи 1510. Порядок

Python 3.4 "Time limit exceeded" test№19 What's wrong?
Послано Danya 22 окт 2015 01:30
What is the test №19?

""
from sys import stdin
from collections import Counter

def search():
    tmp = Counter([int(x) for x in stdin])
    return [i for i in tmp.keys() if tmp[i] == max(tmp.values())][0]
search()
"""

Edited by author 22.10.2015 01:31
Re: Python 3.4 "Time limit exceeded" test№19 What's wrong?
Послано Alexander Vasilyev`~ 13 июн 2018 20:51
Maybe replace search() with print(search())?
That was a joke, but when I tried to submit this code, i got WA1.
The test is ok, but your code is not optimal. Your code calculates max(tmp.values()) every time, and it is a costly operation.
And here is my optimized (WA23, because there is another drawback in your solution) version of it:
from sys import stdin
from collections import Counter

def search():
    tmp = Counter(map(int, stdin))
    on2_to_on = max(tmp.values())
    print(next((i for i in tmp.keys() if tmp[i] == on2_to_on)))
search()
Or:
[code deleted]
But with 1 additional line I got AC. Btw, the Python is relatively slow and uses a bit more memory too.

Edited by moderator 24.11.2019 13:31