Editorial for WC '17 Contest 4 J4 - Efficiency


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.

Let (r, c) denote the cell in row r and column c of the grid. We'll first need to find Hawkeye's position (R_H, C_H). To do so, we can iterate over all R \times C cells in the grid, and when we encounter a cell (r, c) with the value H, we can set R_H to r and C_H to c.

From there, we'll need to consider all four possible directions for Hawkeye's shot, simulating how many dead soldiers each of them would result in and then using the maximum of the four values as our answer. To simulate Hawkeye shooting North, we can iterate a variable r between 1 and R_H-1 (inclusive), while counting the number of cells (r, C_H) with the value C. The other three directions can be handled similarly.


Comments

There are no comments at the moment.