tan_delhi's blog

By tan_delhi, history, 21 month(s) ago, In English

Recently the Educational round 144 , Python Code for D question that used iterative approach Dynamic programming resulted in TLE.

However C++ code for the same passed in 170 ms

Python Code — https://p.ip.fi/hwgL C++ Code — https://p.ip.fi/Jsdm

vovuh , adedalic, please look into the matter.

This is probably the 3rd or 4th-time python gave TLE but C++ did not. Why at all keep python a language option if not tested properly

  • Vote: I like it
  • +9
  • Vote: I do not like it

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by tan_delhi (previous revision, new revision, compare).

»
21 month(s) ago, # |
  Vote: I like it +3 Vote: I do not like it

Hey. See my last submission. Python is not very fast sometimes, but if you copy Fast input-output, it can pass (like 1949ms/2000ms). Of course use Pypy3-64

  • »
    »
    21 month(s) ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks bro, everyday is a new experiment with python

»
21 month(s) ago, # |
  Vote: I like it +26 Vote: I do not like it

All C++ enjoyers after reading this post are like

»
21 month(s) ago, # |
Rev. 5   Vote: I like it 0 Vote: I do not like it

You can try changing -math.inf to float("-inf") and use PyPy 3-64 over PyPy 3

»
21 month(s) ago, # |
  Vote: I like it 0 Vote: I do not like it

C++ is much faster than Python (that is why many programmer prefers using C++ over Python). See this, I use the same algorithm for this problem and uhhh... C++ is about 15 times faster.

So C++ is worth learning.

»
21 month(s) ago, # |
  Vote: I like it +3 Vote: I do not like it

I slightly altered your code and now it passes. You used fast input, but didn't use fast output, calling print function multiple times is slow af. Also not quite sure if imporing full module instead of a few functions will slow down your code, but I have a feeling that it does. Here is the submission 195542299