Bob's Shortest Non-common Substring

View as PDF

Submit solution

Points: 20 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

Having learned about the longest common substring and longest common subsequence, Bob is now interested in finding the shortest non-common substring and subsequence between two strings. Given two strings A and B, Bob wants to find out the following numbers:

  • L_1: The length of the shortest substring in A that is not a substring in B.
  • L_2: The length of the shortest substring in A that is not a subsequence in B.
  • L_3: The length of the shortest subsequence in A that is not a substring in B.
  • L_4: The length of the shortest subsequence in A that is not a subsequence in B.

Your task is to write a program to help Bob find these numbers.

Input Specification

The first line of input contains the string A (|A| \le 2\,000).

The second line of input contains the string B (|B| \le 2\,000).

Both strings A and B consist of only lower alphabetical letters.

Output Specification

Output four lines, where each line contains one number in the above order from L_1 to L_4. If there is no such answer, output -1.

Constraints

Subtask Points Additional constraints
1 20 |A|, |B| \le 20.
2 30 |A|, |B| \le 500.
3 50 No additional constraints.

Sample Input 1

aabbcc
abcabc

Sample Output 1

2
4
2
4

Explanation

  • aa is the shortest substring in A, but not a substring in B;
  • aabb is the shortest substring in A, but not a subsequence in B;
  • ac is the shortest subsequence in A, but not a substring in B;
  • aabb is the shortest subsequence in A, but not a subsequence in B.

Sample Input 2

aabbcc
aabbcc

Sample Output 2

-1
-1
2
-1

Comments

There are no comments at the moment.