Editorial for LCC/Moose '19 Contest 1 S2 - Siege


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.

Submitting an official solution before solving the problem yourself is a bannable offence.

Author: Riolku

Since there are no penalties for moving around the castle, you can simply take the smallest section from each layer to optimally enter the castle.

To do this, you can store the grid as a 2-d array and for each layer, process the top, left, bottom and right rows individually to process all items.

Alternatively, process the rows in order like so. Say we are processing the i^\text{th} row ( 0 \le i < N ). Now the first and last  i columns are for an outer layer, and the inner  2 \times (N - i) columns are part of the ith layer.

You can then do the same thing for the last N rows, but in reverse, and sum the minimum values at the end.


Comments

There are no comments at the moment.