QOJ.ac

QOJ

Limite de temps : 1 s Limite de mémoire : 2048 MB Points totaux : 100

#4195. 寻找 Waldo

Statistiques

你可能知道《威利在哪里?》(Where is Waldo?)这个游戏。在这个游戏中,你需要在人群中找到一个叫威利的人。本题与之类似。你需要找到一个面积最小的轴对齐矩形,使其包含字母 W、A、L、D 和 O,而这些字母隐藏在其他字母的海洋中。

图 L.1:第二个样例的示意图。

输入格式

输入包含: 一行,包含两个整数 $h$ 和 $w$ ($1 \le h, w \le 10^5, h \cdot w \le 10^5$),表示字母网格的高度和宽度。 $h$ 行,每行包含 $w$ 个大写字母 A-Z,表示字母网格。

输出格式

输出包含字母 W、A、L、D 和 O 中每一个至少一次的最小轴对齐矩形的面积。如果不存在包含这些字母的矩形,则输出 impossible

样例

样例输入 1

5 5
ABCDE
FGHIJ
KLMNO
PQRST
VWXYZ

样例输出 1

25

样例输入 2

5 10
ABCDEABCDE
FGHIJFGHIJ
KLMNOKLMNO
PQRSTPQRST
VWXYZVWXYZ

样例输出 2

20

样例输入 3

5 10
WAALDLODOW
AWWLAOODOW
LOLADOWALO
ADALLLWWOL
WWOOAAAALO

样例输出 3

5

样例输入 4

2 3
WAL
TER

样例输出 4

impossible

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.