Python run time more than 1 sec

Hi all, I want to ask the time limit 1sec given in the contest questions, is it for c++ or all the languages because when I run my python code for a problem it is generally 4 times that of c++. should I consider coding in python or c++. In the long run, will I get stuck because I choose Python.

for example, if I write the solution to MYSARA problem of march Cookoff 2020 in python using functions
https://www.codechef.com/viewsolution/30750605
my time is 4.76 sec

if I write with the function, only the procedural programming without any function
https://www.codechef.com/viewsolution/30750567
I got 2.2 sec

validate time here(https://www.codechef.com/status/MYSARA,jugshaurya)
Now if I write the code in c++ it will run under a second.
Questions: -

  1. Why is that so? if all the three codes are of time complexity O(NlogN)
  2. Should c++ be chosen over python for competitive coding?
  3. Are online platforms take the language runtimes into account(which I don’t think so in long challenges.)
  4. Are we living in the c++ dominated competitive world? :slight_smile:

Answers:

  • (1) Python is interpreted, unlike C++ which is compiled.

  • (3) It depends from platform to platform. (CodeForces does)

  • (2) It should be your choice but, I would say yes. I used to code in JAVA but eventually shifted to C++ for CP. Also, Python does not have defined primitives (like int, float,etc.) which is not good for someone starting programming. (Again, should be your choice)

  • (4) Yes, sorry bud. :slightly_frowning_face:

Edit:

Check out this link for more info.

2 Likes

There do seem to be Problems that almost certainly can’t be solved within the time limits if you use Python - Python’s speed vs C++ varies enormously.

1 Like

What about codechef ? Does it take into account that python is interpreted. @admin

Stuff about overflows and handling big number operations are best learnt through C++.

Also its supposed to be the fastest.

https://blog.codechef.com/2009/04/01/announcing-time-limits-based-on-programming-language/