日鉄ソリューションズプログラミングコンテスト2022(AtCoder Beginner Contest 257)
G
Prefix Concatenation
AtCoder
⌀ 2078
原题
← Ex→
翻译中…

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.

翻译中…

样例

Input #1
aba
ababaab
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$.
Input #2
atcoder
ac
Output #2
-1
Since it is impossible to express $T$ as a concatenation of prefixes of $S$, print $-1$.
题目信息

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。