QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 32 MB Total points: 40

#17104. PRVA

Statistics

小 Ivica 每天都玩填字游戏。如果你没见过填字游戏,它是在一个 $R \times C$ 的网格上进行的,每个格子要么是空的,要么是被阻挡的。玩家的任务是在连续的空格子中垂直(自上而下)或水平(从左到右)填入单词。

Ivica 的妹妹有一个奇怪的习惯,她喜欢看 Ivica 已经填好的字谜,并从中找出字典序最小的单词。她只考虑长度至少为 2 个字符的单词。

编写一个程序,在给定的填字游戏中找到这个单词。

输入格式

第一行包含两个整数 $R$ 和 $C$($2 \le R, C \le 20$),表示填字游戏的行数和列数。

接下来的 $R$ 行,每行包含一个长度为 $C$ 的字符串。每个字符要么是英文小写字母,要么是表示阻挡格子的字符 #

输入数据保证总是存在解。

输出格式

输出填字游戏中字典序最小的单词。

样例

输入样例 1

4 4
luka
o#a#
kula
i#a#

输出样例 1

kala

输入样例 2

4 4
luka
o#a#
kula
i#as

输出样例 2

as

输入样例 3

4 5
adaca
da##b
abb#b
abbac

输出样例 3

abb

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.