QOJ.ac

QOJ

実行時間制限: 5.0 s メモリ制限: 64 MB 満点: 140

#16993. MONO

統計

Mirko 很快意识到研究数列并不是最好的职业选择,于是他立刻回到了字母表格的生意中。

Mirko 的表格有 $R$ 行 $C$ 列,由小写字母组成。

表格的每个单元格都是大小相同的正方形。我们为这些正方形的顶点分配坐标,使得表格的左上角坐标为 $(0, 0)$,右上角为 $(C, 0)$,左下角为 $(0, R)$,右下角为 $(C, R)$。

如果表格内的一个多边形满足以下条件,我们称其为单字母多边形

  • 其顶点属于上述单元格正方形的顶点集合;
  • 其边平行于坐标轴;
  • 多边形内部的所有字母都相同。

现给出一个满足前两个条件(第三个条件可能满足也可能不满足)的简单多边形。

Mirko 想要知道,通过将给定的多边形向上、下、左、右平移(或其任意组合)且不进行旋转,可以得到多少个不同的单字母多边形。

输入格式

第一行包含两个由空格隔开的整数 $R$ 和 $C$($1 \le R, C \le 500$)。

接下来的 $R$ 行,每行包含恰好 $C$ 个小写字母,表示 Mirko 的表格。

下一行包含一个整数 $V$($4 \le V \le 500$),表示给定多边形的顶点数。

接下来的 $V$ 行,每行包含两个整数 $X, Y$($0 \le X \le C, 0 \le Y \le R$),表示给定多边形顶点的坐标。顶点按顺时针顺序给出。

给定的多边形保证满足上述条件 1 和 2。

输出格式

输出的第一行也是唯一的一行,包含满足条件的多边形数量。

子任务

  • 在占总分 40% 的测试数据中,$R, C$ 和 $V$ 均不超过 20。
  • 在占总分 70% 的测试数据中,$V$ 不超过 20。

样例

输入样例 1

3 3
aaa
aaa
aaa
4
2 0
2 2
0 2
0 0

输出样例 1

4

输入样例 2

3 3
aaa
aba
aaa
4
2 0
2 2
0 2
0 0

输出样例 2

0

输入样例 3

5 4
xyyx
xyyy
xxyy
xxxx
xxxx
8
1 3
1 2
0 2
0 0
2 0
2 1
3 1
3 3

输出样例 3

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.