Блог пользователя tan_delhi

Автор tan_delhi, история, 18 месяцев назад, По-английски

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

  • Проголосовать: нравится
  • +9
  • Проголосовать: не нравится

»
18 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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

»
18 месяцев назад, # |
  Проголосовать: нравится +26 Проголосовать: не нравится

All C++ enjoyers after reading this post are like

»
18 месяцев назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

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

»
18 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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.

»
18 месяцев назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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