Nightmare Brother
시간 제한2초메모리 제한1024 MB
위치가 지정된 부분 문자열 힌트들이 주어질 때, 힌트 하나를 빼고 나머지로 유일하게 정해지는 문자열이 있는지 판정하고 유일, 불가능, 복수 중 하나를 출력한다.
문제
Your brother has a string of length with indices from to . You want to know exactly what string is. To help you, he gives you hints that might help you to figure out . Hint is represented by an integer and a string , indicating that the string appears as a substring of starting from index of . All the hints are unique, that is, there are no hints and such that while and .
However, your brother is known to be mischievous and tells you that there might be at most one false hint among all hints he has given, but he didn’t tell you which.
A string is a possible solution if and only if there exists a set of at least hints (that are assumed to be true) where string 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. If there is more than one possible solution, you should output -2.
입력
Input begins with two integers (; ) representing the number of hints and the length of the scary string, respectively. Each of the next lines contains an integer and a string (; ) representing hint . The string consists of only uppercase characters. It is guaranteed that there are no hints and such that while and .
출력
If there is exactly one possible solution as explained in the problem description above, then output the string in a single line. If there is no possible solution, then output -1 in a single line. If there is more than one possible solution, then output -2 in a single line.