wronganswer.5's blog

By wronganswer.5, history, 12 months ago, In English

This question was asked was in an OA. I was not able to sovle it fully i.e my soln got partially accepted.

Code

I want to solve this problem via memorization as I am not so good at writing bottom-up approach directly.

I took 5 states-> X and Y coordinates of alice and bob and index of the corr(array of position of apples). How to optimize states?

Thanks in advance.

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

| Write comment?
»
12 months ago, # |
  Vote: I like it +12 Vote: I do not like it

Firstly, observe that there are only $$$n+2$$$ locations/coordinates you care about: the $$$n$$$ apples and starting locations of Alice and Bob. So a naive dp state might look like $$$dp[Current\;apple][Alice\;location][Bob\;location]$$$. However this is $$$n^3$$$ and is likely too slow for given constraints.

Hint #1
Hint #2
Solution
  • »
    »
    12 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Really inspiring reduction in dimension.

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

Which college are you from??