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

Автор beginner1010, история, 5 лет назад, По-английски

Hello,

I have recently started learning Python. I tried F. Vus the Cossack and a Graph from Codeforces Round #571 (Div. 2). To solve this problem, first I wrote a recursive function to find an Euler circuit, and I got MLE (Memory Limit Exceeded). Using an iterative method (with stack) did not help me either.

You may find the Python implementation here in 59832390

I would appreciate if you give me some hints to make the implementation more efficient in terms of memory. Of course, any hint to make it faster is welcomed.

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

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

I implemented the same solution in Java. It gets TLE: 59876165.

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

Hmm so while I agree the ML and TL is pretty tight, this problem is definitely possible in python using PyPy.

Here is my first try with PyPy2, it got AC.

Here are two solutions using the header that I normally use

I think the main thing that takes down the memory cost in python is using pure integer lists, this is because PyPy has a special strategy for pure integer lists, making it only use 4 bytes per integer. Note that this is not true for tuples, nor list of tuples, nor lists containing big integers.