PROBLEM LINK:Author: Praveen Dhindwa DIFFICULTY:Cakewalk PREREQUISITES:None PROBLEM:Given a grid filled with '*' and '.', find the cell in the grid from where the distance to the farthest '*' marked cell is travelled in least time. Report that time. EXPLANATION: Subtask 1 How do we calculate this time? Let us say the perfume is released at cell $(x_1,\,\, y_1)$ and reaches cell $(x_2,\,\, y_2)$. How much time will it take given the movement constraints? The answer is $max(x_2  x_1,\,\, y_2y_1) + 1$. How did we get this? Let us assume without loss of generality that $x_2  x_1$ $<$ $y_2  y_1$. Since, diagonal movement is allowed, both xcoordinate and ycoordinate can be incremented by 1 simultaneously in the required direction of movement. Once the required row or column has been reached, the remaining distance along other dimension can be travelled in a straight line. Hence, $max(x_2  x_1,\,\, y_2y_1)$. The extra plus 1 is because it takes 1 second for the perfume to act on the cell it is released in. The proof of why we only need to consider the $2N$ points is trivial and left to the reader to work out. The complexity of this approach is $\mathcal{O}(TN^2M)$ which is sufficient for the constraints of this subtask. Subtask 2 Then the answer we are looking for is $\frac{max(max\_colmin\_col,\,\, max\_rowmin\_row)}{2} + 1$. Why are we taking the averages of the min and max column and row numbers? This is because it is optimal to release the perfume at the mean point. If the perfume is released at any other point, the time taken to reach at least one of the extremes will be more than in the case when it is released at the mean. The time is calculated by the same logic as given in the subtask 1 solution. This solution is $\mathcal{O}(TNM)$. OPTIMAL COMPLEXITY:$\mathcal{O}(NM)$ per test case. SAMPLE SOLUTIONS:
This question is marked "community wiki".
asked 29 Dec '15, 14:32

Link to all 3 sample solutions are broken. Can you please verify ONCE after posting that these links work?? Or else post some link to a reliable site like ideone. answered 27 Feb '16, 15:39

in short we just find the top bottom left right houses and then calculate the time from the maximum of(bottomtop) and (rightleft) answered 16 Jan '16, 11:25

Can anyone please point out the mistake in following code like I've used bfs to find largest distance from any point to the other and took the median of that distance.And I've got 60 points for 2nd subtask. Link to my submission is https://www.codechef.com/viewsolution/9118654 answered 11 Jan '16, 15:59
