#P15618. [ICPC 2022 Jakarta R] Nightmare Brother

[ICPC 2022 Jakarta R] Nightmare Brother

题目描述

Your brother has a string SS of length MM with indices from 11 to MM. You want to know exactly what string SS is. To help you, he gives you NN hints that might help you to figure out SS. Hint ii is represented by an integer XiX_i and a string TiT_i, indicating that the string TiT_i appears as a substring of SS starting from index XiX_i of SS. All the hints are unique, that is, there are no hints ii and jj such that iji \neq j while Xi=XjX_i = X_j and Ti=TjT_i = T_j.

However, your brother is known to be mischievous and tells you that there might be at most one false hint among all NN hints he has given, but he didn't tell you which.

A string SS is a possible solution if and only if there exists a set of at least N1N - 1 hints (that are assumed to be true) where string SS is the only string consistent with all of the hints in the set.

You would like to find a possible solution. If there is no possible solution, you should output 1-1. If there is more than one possible solution, you should output 2-2.

输入格式

Input begins with two integers NN MM (1N1001 \leq N \leq 100; 1M1001 \leq M \leq 100) representing the number of hints and the length of the scary string, respectively. Each of the next NN lines contains an integer and a string XiX_i TiT_i (1Xi,Ti1 \leq X_i, |T_i|; Xi+Ti1MX_i + |T_i| - 1 \leq M) representing hint ii. The string TiT_i consists of only uppercase characters. It is guaranteed that there are no hints ii and jj such that iji \neq j while Xi=XjX_i = X_j and Ti=TjT_i = T_j.

输出格式

If there is exactly one possible solution as explained in the problem description above, then output the string SS in a single line. If there is no possible solution, then output 1-1 in a single line. If there is more than one possible solution, then output 2-2 in a single line.

3 11
5 JAKARTA
1 ICPC
3 BINUS
ICPCJAKARTA
3 9
6 EX
8 AM
1 FINAL
FINALEXAM
3 8
1 GRAD
5 UAL
6 ATE
-1
3 5
1 BIN
4 US
4 OM
-2

提示

Explanation for the sample input/output #1

The only possible SS is ICPCJAKARTA assuming hint 33 is false. If the false hint is assumed to be one of the others, then there is no string consistent with the other two hints. Similarly when no hint is assumed false.

Explanation for the sample input/output #2

The only possible SS is FINALEXAM assuming no hint is false. If any of the hints are assumed to be false, then there is more than one string consistent with the rest of the hints.

Explanation for the sample input/output #3

There is no possible solution.

  • Assuming no hint is false: There is no string consistent with all the hints.
  • Assuming hint 11 is false: There is no string consistent with the other two hints.
  • Assuming hint 22 is false or hint 33 is false: There is more than one string consistent with the other two hints.

Explanation for the sample input/output #4

There are 22 possible solutions: BINOM (assuming hint 22 is false) and BINUS (assuming hint 33 is false).