#P3271. Squares on a Grid
Squares on a Grid
Squares on a Grid
God said, "Don't be round, be square," and thus this problem was born. You are given a grid with N rows and M columns of cells, which yields ( (N+1) \times (M+1) ) grid points. However, God removed K of these points. Your task is to count the number of squares whose four vertices are all among the remaining grid points. A square is defined as four distinct points that form a square (the square may be arbitrarily oriented, not necessarily aligned with the axes).
For clarity, note that the total number of grid points before deletion is given by ( (N+1) \times (M+1) ). The input specifies K removed points, and only the remaining points can be used to form squares.
A sample square may be the axis-aligned one or a rotated square as long as all its vertices belong to the set of remaining points.
inputFormat
The first line contains three integers N, M, and K, where N and M denote the number of rows and columns of cells, respectively, and K is the number of removed grid points. Each of the next K lines contains two integers r and c (with 0 ≤ r ≤ N and 0 ≤ c ≤ M) indicating the coordinates of a removed point. The grid originally has all points ((r, c)) for 0 ≤ r ≤ N and 0 ≤ c ≤ M, with the listed K points removed.
outputFormat
Output a single integer — the total number of squares whose four vertices are among the remaining grid points.
sample
1 1 0
1