Enormous Input and Output Test

alex23 wuwei23 at gmail.com
Sat Oct 3 23:43:31 EDT 2009


On Oct 3, 11:54 pm, n00m <n... at narod.ru> wrote:
> I need your help to understand howhttp://www.spoj.pl/problems/INOUTEST/
> can be passed in Python.
>
> My code for this is:
> ===========================================
> import psyco
> psyco.full()
>
> import sys
>
> def noo(b):
>     b = b.split()
>     return str(int(b[0]) * int(b[1])) + '\n'
>
> def foo():
>     ##sys.stdin = open('D:/1583.txt', 'rt')
>     a = sys.stdin.readlines()
>     a = a[1:int(a[0]) + 1]
>     a = map(noo, a)
>     sys.stdout.writelines(a)
>
> foo()
> ===========================================
>
> But it gets "Time Limit Exceeded" verdict.
> Any ideas?

map() is really at its most efficient when used with built-ins, not
user defined functions. In those cases, I believe you're better off
using a for-loop or list comprehension. Also: are you sure they
support psyco? It's not part of stdlib...

I thought something simpler might work:

import sys

sys.stdin.readline()

for line in sys.stdin.readlines():
    nums = map(int, line.split())
    print nums[0] * nums[1]

But although this processes 5.5MB < 2 secs on my PC (which meets the
2.5MB/sec criteria outlined in INTEST), I'm getting the same result
that you are.

Do you know how big the input data set actually is?



More information about the Python-list mailing list