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

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

In the contest Hello 2025 Question 2 (https://mirror.codeforces.com/contest/2057/problem/B).I encountered an interesting issue where the same logic, when implemented in Python, resulted in a Time Limit Exceeded (TLE) error, while the C++ version worked flawlessly within the constraints. This raises an important question about the fairness of using Python in competitive programming. Python, being an interpreted language with slower I/O operations and dynamic typing, tends to be slower than C++, especially when handling large inputs within strict time limits. Contest organizers should ensure that Python solutions are adequately supported by adjusting time limits and testing across all allowed languages to ensure fairness. If Python is offered as a valid contest language, it’s important to apply time multipliers, and set reasonable input sizes that account for Python’s slower performance. As a participant, while optimizing my solution is my responsibility, it’s crucial for contest organizers to consider these language-specific challenges and create a level playing field for all competitors. Python Code:-299626739 C++code:-299702848

I hope that the organizer will atlest try to compensate for this.

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

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

Unfortunately, python has a very exploitable hashing algorithm (due to its predictability). So, pretty much, you should never use the dictionary in python. But if you do, you can do something like this: 299613409. It just xors keys with a random number before adding them to the dictionary. This makes it less predictable.

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

    we have also an exploitable in c++, the "unordered_map", then it is important to know how your tools works xD

    Language is a tools, you need to know some aspects in deep to get the best performance, whether it is the tool or some algorithms.

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

This is not Python related, at least not directly. The reason your solution got TLE is not because Python is slower than C++, it's because Counter uses a hash table and someone submitted a hack that causes collisions in the hash table, resulting in $$$O(n^2)$$$ time complexity. C++ users which used unordered_map got TLE for the very same reason.

In general, using any data structure that uses hashing with its default hash means you're almost certainly going to get hacked/FST-ed. Either use a custom, safer hash, or use structures that don't rely on hashing.

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

Even I got tle but I did not use counter I used simple dictionary. https://mirror.codeforces.com/contest/2057/submission/299699660

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

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