Блог пользователя abdulmusavir.juraev

Автор abdulmusavir.juraev, история, 27 часов назад, По-русски

Hi Codeforces!

Many people say that Python is too slow for competitive programming and that everyone should switch to C++. While C++ is undeniably faster, I believe Python is still an amazing language for problem-solving if used correctly.

Here are a few things I learned while solving problems in Python on Codeforces:

1. PyPy 3 is a lifesaver

Never submit in pure Python 3 if execution time matters. PyPy 3 JIT compiler makes loops significantly faster.

2. Avoid input() in big loops

Using sys.stdin.read().split() instead of standard input() reduced my I/O time significantly on large datasets.

3. Python's hidden superpowers

  • Built-in support for Big Integers (no need to worry about 64-bit overflow).
  • Extremely fast string manipulations and list comprehensions.
  • Easy-to-read syntax which lets you focus purely on the logic during contests.

Question for the community: What is your peak rating using Python/PyPy? Do you think it's worth switching to C++ after reaching Candidate Master, or can PyPy carry even higher?

Let’s discuss in the comments!

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

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

Auto comment: topic has been translated by abdulmusavir.juraev (original revision, translated revision, compare)

»
26 часов назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

ofc ill switch to cpp, it lets u understand what u r doing better and is faster

(and its only allowed language in inoi)

EDIT: there is a gm who only used python in his every contest, so it is definitely possible.

»
19 часов назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Если ты достиг рейтинга кандидата в мастера написав при этом только в Питоне, это не значит что если ты прейдёшь в другой язык то будешь как новичок или ученик, потому что ты достиг этого рейтинга только блогодаря знаниям спортивного программирование а не знаниям языка. Да, по началу может быть какие-то трудности в изучение другого языка, но если привыкнешь писать код как в питоне который привык писать то будет легко решать с новым языком задачи.

»
18 часов назад, скрыть # |
← Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

conqueror_of_tourist 3200+ max
pajenegod 2400+ max

both of them have most of their submits in pypy

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

I’m 1800 which is in the top <4% of codeforces users and still use python for implementation light or easy problems, I’m quite well versed in it and it’s very clean and fast to write. I still use C++ for more “heavy duty” problems or specific features but Python definitely has its strengths.

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

Now in order to speed up in contests, I often use Pypy3 unless I encounter problems with tags like data structures, graphs and trees. In the old days I use only one progamming language, C++, now gradually turn to Python:)

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

after you learn how to code in C++, you do not want to write code in python again.