paramsingh's blog

By paramsingh, history, 2 years ago, In English,

Hi there. I've been trying to solve http://www.spoj.com/problems/AKBAR/ for some time, but the only thing I can seem to come up with is starting a BFS from each of the soldiers as the source until the soldier's strength depth. However, that approach gives me a TLE. Any help regarding how to solve this problem would be appreciated. Thanks.

Here's the code for my approach that I tried (TLE): https://gist.github.com/paramsingh/81d728295e6bd01860a0

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

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

say ALLAHU AKBAR and problem will solve itself.

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

using memset in lines 39+40 gave you the TLE

you don't need to do it for every soldier, if any city is previously visited by another soldier, then the flag turns false...

remember that "every city is protected by one and only one soldier.According to Akbar , this is the optimum placement."

if you need more help, just tell me ^_^

  • »
    »
    23 months ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    Oh man, that was a really stupid mistake! Thanks a lot for the help, I've got it accepted now.

    :)

  • »
    »
    13 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you please tell me how to resolve TLE in this code http://ideone.com/ljgRhi ?

    • »
      »
      »
      13 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      rghv same mistake:

      using memset in line 42 gave you the TLE

      you don't need to do it for every soldier, if any city is previously visited by another soldier, then you should return false...

      remember that "every city is protected by one and only one soldier.According to Akbar , this is the optimum placement."

»
13 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Hey, I also used the same approach and getting TLE. Here's my code http://ideone.com/ljgRhi. Any help would be appreciated.