On Sat, Oct 3, 2009 at 6:54 AM, n00m <n...@narod.ru> wrote:
> Hi, py.folk!
>
> I need your help to understand how
> http://www.spoj.pl/problems/INOUTEST/
> can be passed in Python.
<snip>
> def foo():
>    ##sys.stdin = open('D:/1583.txt', 'rt')
>    a = sys.stdin.readlines()

That line is probably a Very Bad Idea (TM) as it reads the *entire*
enormous file into memory *at once*. It would probably be much better
to iterate over the file, thus only reading one individual line at a
time. I'm betting the massive malloc()ing involved with .readlines()
is a large part of the slowness.

<snip>
> But it gets "Time Limit Exceeded" verdict.
> Any ideas?

Cheers,
Chris
--
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to