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

Автор Mohammed_Almasry, история, 4 года назад, По-английски

I got Runtime error on test 17 in python and i don't know why 69797580 . I solved the problem (E. New Reform) in cpp with the same logic and passed 69725502 any help ?? Thanks

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

»
4 года назад, # |
Rev. 4   Проголосовать: нравится +3 Проголосовать: не нравится

Python + Recursion = B A D (Reason ~ link).

Stack Overflow will happen in the case of a linear graph of 10^6 size. What can you do :

1.Use Any Other Language as you did already.(CPP ;-))

2.Use Threading and sys.setrecursionlimit(10**6) as I did (Modified your code and got AC).(69799972).

Example code to increase recursion limit and max stack size in Python.

code

Although it is not recommended since it gives MLE in many cases. Not mine

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +1 Проголосовать: не нравится

    Python + any kind of heavy object handling = bad, and a function call is also an object. Python + C modules for heavy computation = perfectly fine.

    Check out Python bindings for C libraries. When anything from a module implemented in C is used in Python, there are sooo many checks and conversions, everything is wrapped in a PyObject* and it's just way too costly. If you avoid these kinds of costly things, e.g. with Numpy array manipulation (=implemented in C) or JIT, working with large data can still be pretty fast.