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

Автор yodacodes, история, 5 часов назад, По-английски

Problem link: https://codeforces.me/problemset/problem/2060/C

1st Submission: https://codeforces.me/problemset/submission/2060/305937191

2nd Submission: https://codeforces.me/problemset/submission/2060/305932678 Language used: Python

Not an input/output related issue.

After my submission, I checked some accepted solutions. Some of them even sort the numbers before solving. It is supposed to take nlog(n).

In any case I tried to sort the map keys, so that I don't have to iterate through all map/dictionary items. But even then I'm getting TLE. Is it the choice of data structure?

Can someone help me understand what is going wrong. I am trying to learn for future problems.

Also, would be great if someone can share any resource for python optimizations to avoid TLE

New user posting for the 1st time. Please let me know if I missed any information.

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

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

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

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

I'm not python master, so I don't really know if your solution is acceptable, but:

  1. try not to rely on hashmap/dictionaries 305951696

  2. try fast input/output sys.stdin.read, sys.stdin.write

Edit: wrong submission number

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

You can use the two pointer way since if Alice chooses a number and that is possible to be k minus a = b then Bob will choose b, otherwise, he will choose anything else that a plus b not equal to k: My submission: my code

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

i would generally suggest you to try C++ for once cuz python processes every single line which makes it slower in the cases, of recursions and loops, or the alternative way is the learn to use threadings i genreally use python for ML and stuff

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

Python maps have a similar flaw to C++ unordered maps, where they can become worst case O(n) per operation (see https://codeforces.me/blog/entry/62393 ). I'm not sure if there is a great way to get around this, but I have 2 ideas

  • Find a python implementation of a red-black tree (which is what c++ uses for its map) and use it instead of map / set

  • Use C++, I know it might be hard, but trust me it is worth it.