#P4112. [HEOI2015] 最短不公共子串

    ID: 3048 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2015各省省选河北后缀自动机,SAMO2优化广度优先搜索,BFS后缀数组,SA

[HEOI2015] 最短不公共子串

Description

Tired of problems about the longest common substrings and subsequences, you decide to go the other way.

Definitions:

  • A "substring" of a string is a contiguous segment of it. For example, bcd is a substring of abcdef, but bde is not.
  • A "subsequence" of a string is a segment that does not need to be contiguous. For example, bde is a subsequence of abcdef, but bdd is not.

Given two lowercase strings a,ba, b, please compute:

  1. A shortest substring of aa that is not a substring of bb.
  2. A shortest substring of aa that is not a subsequence of bb.
  3. A shortest subsequence of aa that is not a substring of bb.
  4. A shortest subsequence of aa that is not a subsequence of bb.

Input Format

There are two lines, each containing a string of lowercase letters, representing aa and bb respectively.

Output Format

Output 44 lines, each containing one integer, representing the lengths of the answers to the above 44 questions in order. If there is no valid answer, output 1-1.

aabbcc
abcabc
2
4
2
4
aabbcc
aabbcc
-1
-1
2
-1

Hint

Constraints:

  • For 20%20\% of the testdata, the lengths of aa and bb do not exceed 2020.
  • For 50%50\% of the testdata, the lengths of aa and bb do not exceed 500500.
  • For 100%100\% of the testdata, the lengths of aa and bb do not exceed 20002000.

Translated by ChatGPT 5