#abc257g. G - Prefix Concatenation

G - Prefix Concatenation

Score : 600600 points

问题描述

给定两个由小写英文字母组成的字符串 SSTT

找出最小的正整数 kk,使得你可以选择(不一定互不相同)SSkk 个前缀,使得它们连接起来与 TT 相吻合。

换句话说,找到最小的正整数 kk,使得存在一个包含 11S|S| 之间的整数的 kk 元组 (a1,a2,,ak)(a_1, a_2, \ldots, a_k),满足以下条件:

T=Sa1+Sa2++SakT = S_{a_1} + S_{a_2} + \cdots + S_{a_k}

其中,SiS_i 表示从第 11 个字符到第 ii 个字符的 SS 的子串,而 $+$ 表示字符串的连接操作。

如果无法使它与 TT 相吻合,则输出 1-1

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given two strings SS and TT consisting of lowercase English letters.

Find the minimum positive integer kk such that you can choose (not necessarily distinct) kk prefixes of SS so that their concatenation coincides with TT.

In other words, find the minimum positive integer kk such that there exists a kk-tuple (a1,a2,,ak)(a_1,a_2,\ldots, a_k) of integers between 11 and S|S| such that
T=Sa1+Sa2++SakT=S_{a_1}+S_{a_2}+\cdots +S_{a_k}, where SiS_i denotes the substring of SS from the 11-st through the ii-th characters and ++ denotes the concatenation of strings.

If it is impossible to make it coincide with TT, print 1-1 instead.

Constraints

  • 1S5×1051 \leq |S| \leq 5\times 10^5
  • 1T5×1051 \leq |T| \leq 5\times 10^5
  • SS and TT are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

SS

TT

Output

Print the minimum positive integer kk such that you can choose kk prefixes of SS so that their concatenation coincides with TT. It is impossible to make it coincide with TT, print 1-1 instead.

Sample Input 1

aba
ababaab

Sample Output 1

3

T=T= ababaab can be written as ab + aba + ab, of which ab and aba are prefixes of S=S= aba.
Since it is unable to express ababaab with two or less prefixes of aba, print 33.

Sample Input 2

atcoder
ac

Sample Output 2

-1

Since it is impossible to express TT as a concatenation of prefixes of SS, print 1-1.

update @ 2024/3/10 10:56:14