QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 2048 MB Total points: 100

#5539. 噩梦兄弟

Statistics

你的兄弟有一个长度为 $M$ 的字符串 $S$,其下标从 $1$ 到 $M$。你想确切地知道字符串 $S$ 是什么。 为了帮助你,他给了你 $N$ 条提示。第 $i$ 条提示由一个整数 $X_i$ 和一个字符串 $T_i$ 表示,含义是字符串 $T_i$ 是 $S$ 从下标 $X_i$ 开始的子串。所有的提示都是唯一的,即不存在 $i \neq j$ 使得 $X_i = X_j$ 且 $T_i = T_j$。

然而,你的兄弟以淘气著称,他告诉你,在他给出的 $N$ 条提示中,最多可能有一条是错误的,但他没有告诉你哪一条是错的。

一个字符串 $S$ 是一个可能的解,当且仅当存在一个至少包含 $N-1$ 条提示的集合(这些提示被假定为真),使得字符串 $S$ 是唯一符合该集合中所有提示的字符串。

你需要找到一个可能的解。如果没有可能的解,你应该输出 $-1$。如果有超过一个可能的解,你应该输出 $-2$。

输入格式

输入的第一行包含两个整数 $N$ 和 $M$ ($1 \le N \le 100; 1 \le M \le 100$),分别表示提示的数量和字符串的长度。接下来的 $N$ 行,每行包含一个整数 $X_i$ 和一个字符串 $T_i$ ($1 \le X_i, |T_i|; X_i + |T_i| - 1 \le M$),表示第 $i$ 条提示。字符串 $T_i$ 仅由大写字母组成。保证不存在 $i \neq j$ 使得 $X_i = X_j$ 且 $T_i = T_j$。

输出格式

如果存在且仅存在一个如题目描述中所述的可能解,则输出字符串 $S$。如果没有可能的解,则输出 $-1$。如果有超过一个可能的解,则输出 $-2$。

样例

样例输入 1

3 11
5 JAKARTA
1 ICPC
3 BINUS

样例输出 1

ICPCJAKARTA

说明 1

假设第 3 条提示是错误的,则唯一可能的 $S$ 是 ICPCJAKARTA。如果假设其他提示中的某一条是错误的,则不存在符合其余两条提示的字符串。同样,当假设没有提示是错误的时候,也不存在符合所有提示的字符串。

样例输入 2

3 9
6 EX
8 AM
1 FINAL

样例输出 2

FINALEXAM

说明 2

假设没有提示是错误的,则唯一可能的 $S$ 是 FINALEXAM。如果假设其中任何一条提示是错误的,则会有超过一个字符串符合其余的提示。

样例输入 3

3 8
1 GRAD
5 UAL
6 ATE

样例输出 3

-1

说明 3

没有可能的解。 假设没有提示是错误的:不存在符合所有提示的字符串。 假设第 1 条提示是错误的:不存在符合其余两条提示的字符串。 * 假设第 2 条或第 3 条提示是错误的:有超过一个字符串符合其余的提示。

样例输入 4

3 5
1 BIN
4 US
4 OM

样例输出 4

-2

说明 4

有两个可能的解:BINOM(假设第 2 条提示是错误的)和 BINUS(假设第 3 条提示是错误的)。

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.