vsanjay_nitdgp's blog

By vsanjay_nitdgp, history, 9 years ago, In English

this is my solution http://ideone.com/49SCl3 for spoj problem

http://www.spoj.com/problems/MRECAMAN/en/

could anyone pls say why am i getting TLE

THANKS IN ADVANCE

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

| Write comment?
»
9 years ago, # |
  Vote: I like it +1 Vote: I do not like it

find function work in O(N), try to use map or set to check if the new element is in the sequence or not.

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

I got AC using this code. ( link ) = the same as yours, but little modified. Method find in vector works in O(N). So, your solution was O(N*N). Set do the same in O(logn) time.