yodacodes's blog

By yodacodes, history, 3 hours ago, In English

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

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

2nd Submission: https://codeforces.net/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.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

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

»
2 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

»
84 minutes ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

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

»
54 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

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