102576: [AtCoder]ABC257 G - Prefix Concatenation

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

You are given two strings $S$ and $T$ consisting of lowercase English letters.

Find the minimum positive integer $k$ such that you can choose (not necessarily distinct) $k$ prefixes of $S$ so that their concatenation coincides with $T$.

In other words, find the minimum positive integer $k$ such that there exists a $k$-tuple $(a_1,a_2,\ldots, a_k)$ of integers between $1$ and $|S|$ such that
$T=S_{a_1}+S_{a_2}+\cdots +S_{a_k}$, where $S_i$ denotes the substring of $S$ from the $1$-st through the $i$-th characters and $+$ denotes the concatenation of strings.

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

Constraints

  • $1 \leq |S| \leq 5\times 10^5$
  • $1 \leq |T| \leq 5\times 10^5$
  • $S$ and $T$ are strings consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

$S$
$T$

Output

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


Sample Input 1

aba
ababaab

Sample Output 1

3

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


Sample Input 2

atcoder
ac

Sample Output 2

-1

Since it is impossible to express $T$ as a concatenation of prefixes of $S$, print $-1$.

Input

题意翻译

给定仅存在小写英文字母的字符串 $ S, T $。你需要将 $ T $ 分割成 $ k $ 个 $ S $ 的前缀(或着说用 $ S $ 的若干个前缀组成 $ T $),最小化 $ k $,输出最小值。若 $ k $ 不存在输出 `-1`。

Output

得分:600分 部分 问题描述 你有两个由小写英文字母组成的字符串S和T。 找出最小的正整数k,使得你可以选择(不一定不同)k个S的前缀,使得它们的拼接与T相同。 换句话说,找到最小的正整数k,使得 存在一个由1到|S|之间的整数构成的k元组(a1, a2, ..., ak),使得 T = Saa2 + ... + Sak 其中Si表示S从第1个到第i个字符的子串,+表示字符串的拼接。 如果无法使其与T相同,则打印-1。 部分 约束条件 1 <= |S| <= 5 * 10^5 1 <= |T| <= 5 * 10^5 S和T是由小写英文字母组成的字符串。 输入格式 输入格式如下: S T 输出格式 打印一个最小的正整数k,使得你可以选择k个S的前缀,使得它们的拼接与T相同。 如果无法使其与T相同,则打印-1。 样例输入1 aba ababaab 样例输出1 3 T = "ababaab" 可以表示为 "ab" + "aba" + "ab",其中"ab"和"aba"是S = "aba"的前缀。 由于无法用"aba"的两个或更少的前缀表示"ababaab",因此打印3。 样例输入2 atcoder ac 样例输出2 -1 由于无法用S的前缀表示T,因此打印-1。

加入题单

算法标签: