QOJ.ac

QOJ

時間限制: 5 s 記憶體限制: 1024 MB 總分: 100

#13876. 护身符

统计

Caitlyn 正在调查另一个案子。她这次最大的线索是一个小护身符,上面有一个 $R \times C$ 的字符网格。

她从一个线人那里得知,这个护身符上有一个秘密代码。她目前还不确定这个代码是什么,但知道它满足以下性质:

  • 该代码在恰好 $x$ 行中作为子串出现,且不在任何其他行中出现。
  • 该代码在恰好 $y$ 列中作为子串出现,且不在任何其他列中出现。
  • 在满足前两个条件的所有字符串中,该代码的长度最大。
  • 在满足前三个条件的所有字符串中,该代码的字典序最小。
  • 该代码的长度大于零。

一个字符串在某一行中作为子串出现,是指当从左到右阅读该行时,它作为该行中连续的字符序列出现。一个字符串在某一列中作为子串出现,是指当从上到下阅读该列时,它作为该列中连续的字符序列出现。对于两个等长的字符串 $S$ 和 $T$,$S$ 的字典序小于 $T$ 是指存在一个索引 $k$,使得对于所有 $i < k$ 都有 $S_i = T_i$,且在字母表中 $S_k$ 排在 $T_k$ 之前。

Caitlyn 知道 $x$ 和 $y$,但她仍然找不到这个代码,她开始怀疑那个线人只是在浪费她的时间。你能设计一个算法来帮助 Caitlyn 破解这个代码吗?

输入格式

第一行包含四个整数 $R, C, x$ 和 $y$($1 \le R \times C \le 2 \cdot 10^5$,$0 \le x \le R$,$0 \le y \le C$,$x + y > 0$)。

接下来的 $R$ 行,每行包含一个长度为 $C$ 且仅由小写字母 a-z 组成的字符串,表示护身符。

输出格式

输出一行,包含如上所述的秘密代码。如果不存在这样的代码,则输出 -1

样例

输入样例 1

3 3 2 2
xba
bab
acc

输出样例 1

ba

输入样例 2

3 3 2 2
aba
bab
acc

输出样例 2

ab

输入样例 3

3 3 2 2
aba
bab
abc

输出样例 3

ba

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.