← All problemsSign in

Chefland and Average Distance

Chefland is a grid with $N$ rows and $M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them. For each $d$ between $1$ and $N+M-2$ inclusive, Chef wants to calculate the number of unordered pairs of distinct houses with distance equal to $d$. Please help him! ### Input - The first l

HINT LADDERno hints yet
L1 Observation
L2 Technique
L3 Approach
L4 Pseudo-code
🔒
L5 Full solution
L5 unlocks only if you insist twice
solution.cppC++17

CodeSearch Tutor

Hints, not spoilers — it won’t hand over the full solution unless you insist.

voice by Sarvam AI

Sign in to chat with the tutor and save your progress.

Sign in to start