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

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

So I was doing this problem: https://codeforces.com/contest/1490/problem/F. And I got TLE when I use C++11: https://codeforces.com/contest/1490/submission/144339905 . and C++14: https://codeforces.com/contest/1490/submission/144338420 . but AC when using C++20: https://codeforces.com/contest/1490/submission/144339955 . Can anyone tell me why this is happening?

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

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

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

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

Change unordered_map to map . Time complexity of unordered_map on average is O(1) but it's worst case complexity is O(n)

https://codeforces.com/contest/1490/submission/144341577

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

    Thank you.

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

    So that mean access element of a unordered_map is faster in C++20?

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

      This is a problem from a Div3 contest, which means that this contest had a 12 hours hacking phase. And unordered_map is known to be vulnerable to adversarially constructed input data, which may hit the worst case time complexity. C++20 isn't better. It's just a newer complier, which probably changed its unordered_map implementation a little a bit. So the old hacks need to be adjusted to successfully target it too. See https://codeforces.com/blog/entry/62393