Enormous Input and Output Test
Chris Rebert
clp2 at rebertia.com
Sat Oct 3 19:29:36 EDT 2009
On Sat, Oct 3, 2009 at 6:54 AM, n00m <n00m at 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
More information about the Python-list
mailing list