QOJ.ac

QOJ

Límite de tiempo: 6 s Límite de memoria: 512 MB Puntuación total: 100

#1088. 边界相似度任务

Estadísticas

在 Bytelandia 有一个名为 Border Similarity Undertaking (BSU) 的大型组织。该组织的负责人拥有一张这个伟大国家的地图。地图由一个 $n$ 行 $m$ 列的矩阵 $A$ 表示。矩阵中的每个元素都是一个小写拉丁字母。

BSU 决定建造一座新工厂。工厂可以是任意大小,但必须是矩形的,且其边必须与地图的边平行。此外,正如你从该组织的名字中所推断的那样,要求矩形边界上的所有字母都必须相同。

BSU 的负责人还没有决定在哪里建造工厂。因此,BSU 雇佣你来计算可能的工厂选址数量。

形式化地说,你需要找到满足以下条件的整数元组 $(x_1, y_1, x_2, y_2)$ 的数量:$1 \le x_1 < x_2 \le n$,$1 \le y_1 < y_2 \le m$,且对于所有 $i \in [x_1, x_2]$,$j \in [y_1, y_2]$,满足 $A_{i,y_1} = A_{x_1,j} = A_{x_2,j} = A_{i,y_2}$。

输入格式

第一行包含两个整数 $n$ 和 $m$,表示 Bytelandia 地图的行数和列数 ($1 \le n, m \le 2000$)。

接下来的 $n$ 行,每行包含 $m$ 个小写拉丁字母,逐行描述矩阵 $A$。

输出格式

输出 BSU 可以建造新工厂的可能位置数量。

样例

样例输入 1

3 5
zzzzz
zxzxz
zzzzz

样例输出 1

3

样例输入 2

4 4
abbc
bcca
babc
acbb

样例输出 2

0

样例输入 3

12 12
abbabaaaaabb
ababaaaaaabb
aaabbbbbabbb
aabababaaaba
abbbaaabaaba
baaababbbaba
aaaaababbaaa
bbabbbbbabaa
bbbabbaabaaa
aabbbaaaabba
babaabababaa
bababaabaaba

样例输出 3

25

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.