wishcode's blog

By wishcode, history, 4 years ago, In English

Hello everyone.

This post is a request to the competitive coding community to improve the current judging system for python and pypy submissions.

I was trying to solve a DP on Trees problem https://codeforces.net/problemset/problem/919/D here is my solution https://codeforces.net/contest/919/submission/80857731, Firstly I submitted my solution in Python3 I got Time limit exceeded on test 18 , then I tried to submit it in pypy3 and I got a runtime error on test 32, I figured it out that I was using recursive dfs so I have to increase the recursion limit then I used sys.setrecursionlimit to set recursion limit to 300000 and submitted it again in pypy3 now I am getting a memory limit exceeded on test 6, but I am not getting memory limit exceeded on test 6 in python3 instead I am getting Time limit exceeded on test 18 again. why pypy and python have difference for memory limit??

This is not the first time I am going through this type of problem, many times I have to convert the whole code and submit it in c++, which eventually get executed, are we really not capable to solve this problem.

Why a python programmer has to suffer? My request is to improve the judging system or remove python or similar languages from codeforces patform.

  • Vote: I like it
  • -35
  • Vote: I do not like it

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it
»
4 years ago, # |
  Vote: I like it +6 Vote: I do not like it

I faced this sort of problem every now and then. My solution used to get hacked(tle) or sometimes TLE in main tests because I used Python and many people who implemented the same logic in C++ were safe. I love using Python (you can look at my handle as well) at last I shifted to C++. It took me 1-2 months to get habituated. I would ge glad if memory limit and time limit were increased

»
4 years ago, # |
  Vote: I like it +34 Vote: I do not like it

or remove python or similar languages from codeforces patform.
"LoOooOoOLoOOooOoLoOOoOoOOooOooOOLoOooOOoOOoOOL. ROFL. LMAO."

»
4 years ago, # |
Rev. 2   Vote: I like it +23 Vote: I do not like it

What you are seeing is a fundamental issue with Python, it definitely isn't CF's fault. Python was never made to handle deep recursion. The amount of memory it takes to do recursion in Python is insane.

The number one thing to do is just to not code deep recursion in Python, I pretty much never code graph algorithms recursively in Python, instead I do things iteratively. A lot of the time it can be done in a surprisingly simple way.

If you still really want to do deep recursion in Python, I made this a while back https://github.com/cheran-senthil/PyRival/blob/master/pyrival/misc/bootstrap.py . Instead of recursing it abuses generators. With it your submission gets AC 80878227. You can read about the bootstrapper here https://pyrival.readthedocs.io/en/latest/bootstrap.html

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you sir, that was very helpful.

  • »
    »
    11 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    is it always possible to change recursion to loop? what's the programming pattern with stack if you wanted to do something after the recursive call ?

    e.g. def f(): f() // do something