#abc257g. G - Prefix Concatenation
G - Prefix Concatenation
Score : points
问题描述
给定两个由小写英文字母组成的字符串 和 。
找出最小的正整数 ,使得你可以选择(不一定互不相同) 的 个前缀,使得它们连接起来与 相吻合。
换句话说,找到最小的正整数 ,使得存在一个包含 到 之间的整数的 元组 ,满足以下条件:
其中, 表示从第 个字符到第 个字符的 的子串,而 $+$
表示字符串的连接操作。
如果无法使它与 相吻合,则输出 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given two strings and consisting of lowercase English letters.
Find the minimum positive integer such that you can choose (not necessarily distinct) prefixes of so that their concatenation coincides with .
In other words, find the minimum positive integer such that there exists a -tuple of integers between and such that
, where denotes the substring of from the -st through the -th characters and denotes the concatenation of strings.
If it is impossible to make it coincide with , print instead.
Constraints
- and are strings consisting of lowercase English letters.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum positive integer such that you can choose prefixes of so that their concatenation coincides with . It is impossible to make it coincide with , print instead.
Sample Input 1
aba
ababaab
Sample Output 1
3
ababaab
can be written as ab
+ aba
+ ab
, of which ab
and aba
are prefixes of aba
.
Since it is unable to express ababaab
with two or less prefixes of aba
, print .
Sample Input 2
atcoder
ac
Sample Output 2
-1
Since it is impossible to express as a concatenation of prefixes of , print .
update @ 2024/3/10 10:56:14