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

Автор iron_nicko, история, 11 месяцев назад, По-английски

214876910

This is just unfair that my PyPy submission got TLE! Can this be reviewed?

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

»
11 месяцев назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

skill issue

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

because python is slow. I also got TLE on test 42 214898344, and the C++ code is Accepted 215049350

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

I think that your program would have passed if you had written in c++

»
11 месяцев назад, # |
  Проголосовать: нравится +16 Проголосовать: не нравится

Its not an issue related to python slowness, but its related to hash collisions being o(n^2)

sort the array before you use counter and it should pass.

https://codeforces.com/contest/1850/submission/215081606 Passes in 200 ms

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

    nice, new knowledge, thank you

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

    thank you

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

    WOW! it worked! can you please give a brief explanation on why this is the case? How does sorting the array decrease hash collisions? very counter intuitive !

    I tried the same for G as i also used a dictionaries there. it passed test case 14 but unfortunately it still got TLE on test 17. Is there anything i could do with that? Problem G submission

    • »
      »
      »
      11 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится
      1. try random.shuffle on points instead of sorted
      2. make main function
      3. dont loop so many times, when you count u can do it in one for loop
  • »
    »
    10 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    can u explain why sorting the list reduced the runtime?

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

      People have designed the testcase to cause hash collision resulting in n^2. If you sort the array you get rid of the hash collision as elements are inserted in a different order, resulting in o(n)