| 
 | 
вернуться в форум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? 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  |  
  | 
|