Enormous Input and Output Test
wuwei23 at gmail.com
Sun Oct 4 05:43:31 CEST 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
> import sys
> def noo(b):
> b = b.split()
> return str(int(b) * int(b)) + '\n'
> def foo():
> ##sys.stdin = open('D:/1583.txt', 'rt')
> a = sys.stdin.readlines()
> a = a[1:int(a) + 1]
> a = map(noo, a)
> 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:
for line in sys.stdin.readlines():
nums = map(int, line.split())
print nums * nums
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