1 / 4
Sep 2011

Hi, I am getting TLE in http://www.spoj.pl/problems/ABCDEF/3 using Python. I have try a lot of possibilities but none of them has been successful.

Removed after AC.
Lesson: On my PC, the program using defaultdict ran faster than the one using normal dict. On SPOJ, it was the opposite.

defaultdict module has gave me the best results. My program runs the test case 100 1 2 3 ... 100 in about 0.25s in my computer, but it gives TLE in SPOJ.

Besides, if I use

for (a, c) in product(w, w):

instead of

for a in w:
   for c in w:

I got Runtime Error (NZEC), and I do not know why.

Can someone help me?

  • created

    Sep '11
  • last reply

    May '20
  • 3

    replies

  • 964

    views

  • 3

    users

  • 1

    link

As you can conclude from the fact that there is only one AC Python submission among more than 5000 AC submissions, it is not so easy to get a Python solution AC for that (not very difficult) problem.

According to defaultdict you should do some speed comparsion with normal dict not only on your local machine, but also on SPOJ machines, because runtime may depend on different versions of OS and Python itself. I guess that you do not use Python 2.5 on your local machine, otherwise you would have find out the reason for the NZEC using the product() function yourself: It's new in Python 2.6. wink

Thanks numerix. Yes, I use Python 2.6. I did not know that an import error causes a runtime error (NZEC) in SPOJ (I am newbie in Python). I changed defaultdict for normal dict and got AC. I thought that if my program ran faster using defaultdict it would be the same on SPOJ.

8 years later