m_s_t_y's blog

By m_s_t_y, history, 2 years ago, In English

Thisis the code I submitted for this ques. Can someone help me understand why TLE is occurring?

  • Vote: I like it
  • +1
  • Vote: I do not like it

»
2 years ago, hide # |
Rev. 4  
Vote: I like it +4 Vote: I do not like it

unordered_set's insert and find have O(n) time complexity in the worst case. change it to the normal set

»
2 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Turns out the worst case of finding an item in an unordered map or set is O(n). I learnt it too the hard way when I used unordered map in one question then it got hacked later. Guess this was your canon event as well.

»
2 years ago, hide # |
Rev. 3  
Vote: I like it +3 Vote: I do not like it