ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1510. Order

Memory Limit Error Using Dictionary with Python2.7
Posted by jdneo 25 Jun 2014 09:57
I used dictionary in python 2.7 to solve this problem, but got MLE on test#21. Can anybody give me some advise or hint about how to deal with this problem? Thanks a lot!!!

Here is my code:

from sys import stdin

num = int(stdin.readline())
notes = {}
for i in range(num):
    key = int(stdin.readline().strip())
    if notes.has_key(key):
        notes[key] += 1
    else:
        notes[key] = 1
max = -1
note = -1
for key, value in notes.items():
    if value > max:
        note = key
        max = value
print note
Re: Memory Limit Error Using Dictionary with Python2.7
Posted by ombschervister 19 Sep 2015 10:00
I have MLE too :(

def main():

    import sys
    from collections import Counter
    n = raw_input()
    lns = sys.stdin.readlines()
    cnt = Counter(lns)
    print max(cnt, key=cnt.get)[:-1]

main()