Is python is too slow for competitive programming?

This is very sad that I could answer only one problem in February Cook-off using python 3.6.
I just solved some problems by python and after executing it in my IDE I find the answer correct. But after submitting it in CodeChef, I got TLE :sleepy::sleepy:
Is python is too slow for competitive programming?
I got TLE 3 times in this cook-off using python. I think that because I used the nested loop.

1 Like

Yes, python is slow for cp.
Switch to c++ asap.

Also note that getting tle probably means ur algorithm was not optimized. Since most of the judges uses multipliers.

4 Likes

Python is slow, but even if you submit in python switch to PyPy.

Still it’s better to use C++17

2 Likes

Can you give me PyPy tutorial link? or please suggest any book.

Yes, I remember an incident when I solved a problem using same algorithm both in cpp and python, It got accepted in cpp but TLE in python.

1 Like

Just submit the same Python code using PyPy, it would work

3 Likes

Quick reminder of just how variable Python’s performance is.

1 Like

@anon73162591 It’s working. Thanks!

1 Like

may be it will be better if you share your code so that it is easy to find the complexity of that code and discuss on this issue.
because some of my friend have done more than one problem using python in February cook-off.

1 Like

You are right.

1 Like

I am going to post them in specific topic. that will help me much.

1 Like

There are some competitive programming contests in which python would be too slow, but that is not the case here. Codechef gives a multiplier to slow languages like python so that if you write your code efficiently, you won’t get a TLE. I solved three problems in the February Cook-off, all in python 3.

Yes. @violetval The problem was in my code.
if I use this kind of code, then it is ok to get TLE:
for
for
if
if
elif
I like pyhton and I always use it in contest. Just I wasn’t aware about TLE.
if anyone want use python in CC they just have to be careful.

ok i am waiting for that.

1 Like

Although Python would generally too slow if used to implement the exact same algorithm one would in C, sometimes you can make use of the time multiplier or some libraries. Smart exploits may let you use a more time-complex algorithm and still get AC sometimes, but that’s only for some specific problems where you can mostly rely on CPython libraries optimized in C. Additionally, use itertools and other lazy and functional interfaces and you may get some generic algorithms passing time limit.

1 Like