Super Paintball
InterviewTime limit1sMemory limit128 MB
Given up to 100000 opponent positions on an N by N grid, count cells from which a shot along its row, column, or either diagonal would pass through every opponent.
- Level
Medium6 of 10
- Topics
- Brute force, Implementation, Array, Math
- Solved
- No attempts yet
Problem
Bessie is playing a paintball game on a square field. The field is divided into an grid of unit cells (). There are opponents (); opponent stands in the cell at row and column (, ). Several opponents may stand in the same cell.
Bessie's paintball gun fires in any of eight directions: up, down, left, right, and the four diagonals (up-left, up-right, down-left, down-right). She hits an opponent if that opponent lies in the same row, the same column, or on one of the two diagonals through her cell. She can also hit an opponent that shares her own cell.
Bessie will stand in exactly one cell. Count how many of the cells she may choose so that, from that cell, she can hit every one of the opponents.
Input
- Line 1: two space-separated integers and .
- Lines 2 to : line contains two space-separated integers and , the row and column of opponent .
Output
- Line 1: a single integer — the number of distinct cells Bessie may occupy so that she can hit every opponent.
Hint
Consider a field with rows and columns and opponents at , , and (C marks an opponent):
. . . .
C . C .
. . . .
C . . .
From each of the cells , , , , and Bessie can hit all three opponents, so the answer is . Below, B marks a valid cell for Bessie and * marks a cell that is valid and also shared with an opponent:
. . . . . . . .
B . B . * . * .
. B . . => . B . .
B . B . * . B .