P26971 [AtCoder] Cake Cutting
普及+
题目描述

Problem Description

E869120 has made a cake of size $H \times W$. To divide the cake with square1001, they decided to cut it.

The cake is rectangular, and the coordinates of its four vertices are $ (0, 0), (0, H), (W, 0), (W, H) $.

square1001 will cut from the coordinate $ (0, 0) $ towards $(i, H) \ (1 \leq i \leq W)$ or $(W, i) \ (1 \leq i \leq H)$. However, the following conditions must be met:

  • There are $ N $ strawberries on the cake, and they must be divided equally.
  • Cutting through a strawberry will cause it to disappear, so the cut must not pass through any strawberries.
  • The cut must be made towards integer coordinates.

At that time, find all $ P $ such that square1001 can cut from $ (0, 0) $ towards $ P $. If it is not possible to do so, output $ -1 $.

Note that the area of the strawberries is not considered.

Input Format

The input is given in the following format:

$ H $ $ W $ $ N $ $ X_1 $ $ Y_1 $ $ X_2 $ $ Y_2 $ : : $ X_N $ $ Y_N $

$ (X_i, Y_i) $ are the coordinates of the $ i $-th strawberry. The values of $ H, W, N $ are as described in the problem.

Output Format

Output according to the output example below in lexicographical order. If there is no solution, output $ -1 $. Do not include extra spaces or newlines in the output.

Sample Input and Output

Sample Input #1

5 5 2
1 3
4 2

Sample Output #1

(2,5)
(3,5)
(4,5)
(5,3)
(5,4)
(5,5)

Sample Input #2

5 5 5
1 1
1 3
3 3
3 4
4 3

Sample Output #2

-1

Sample Input #3

5 5 2
3 2
4 3

Sample Output #3

-1

Notes/Hints

Constraints

$1 \leq H, W, N \leq 10$

$1 \leq X_i < W$, $1 \leq Y_i < H$

$i \neq j \Rightarrow (X_i, Y_i) \neq (X_j, Y_j)$

Sample Explanation 1

It is possible to cut as shown below. Output according to lexicographical order. ![](/img/other/s8pc-1/98532AA564914B51B5553DD08A2E5E69.png)

Sample Explanation 2

The strawberries are in an odd number, so they cannot be divided equally.

Sample Explanation 3

Only cuts towards integer coordinates are possible.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
5 5 2 1 3 4 2
样例输出
(2,5) (3,5) (4,5) (5,3) (5,4) (5,5)