Editorial for CTU Open Contest 2018 - Security Guards
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.
Submitting an official solution before solving the problem yourself is a bannable offence.
- Fill the grid with the distance to the nearest guard.
- Use BFS with multiple starts.
- Query in constant time.
- Complexity
Alternative solution:
- Fill the grid with on guard positions and otherwise.
- Create 2D prefix sum.
- For each query, use binary search to get the answer.
- Complexity
Comments