#P6652. 「SWTR-5」String
「SWTR-5」String
Problem Description
Little A has a string . He can do the following operation: cut off a prefix or suffix of , with the condition that the removed prefix/suffix is a substring of after the cut. Little A wants to obtain the string . What is the minimum number of operations needed? If it is impossible, output .
Input Format
Two lines, each containing a string, representing and .
Output Format
Output one integer in one line, representing the answer.
abbabb
ba
3
fxofoxxooffoxooo
fox
8
abcdefghijklmnopq
rstuvwxyzz
-1
ycxcy
cxy
-1
Hint
"Sample Explanation"
Sample : $\texttt{abbabb}\to \texttt{abba}\to \texttt{bba}\to \texttt{ba}$. The solution is not unique.
Sample : $\texttt{fxofoxxooffoxooo}\to\texttt{xofoxxooffoxooo}\to\texttt{foxxooffoxooo}\to\texttt{xooffoxooo}\to\texttt{ffoxooo}\to\texttt{ffoxoo}\to\texttt{ffoxo}\to\texttt{ffox}\to\texttt{fox}$. The solution is not unique.
"Constraints and Notes"
This problem uses bundled tests.
- Subtask 1 (1 points): .
- Subtask 2 (9 points): contains only the letter .
- Subtask 3 (15 points): .
- Subtask 4 (17 points): .
- Subtask 5 (18 points): .
- Subtask 6 (15 points): , *testdata is random.
- Subtask 7 (25 points): No special restrictions.
For of the testdata: , character set .
*Random testdata: the characters of are random, character set .
Please pay attention to constant-factor optimization.
"Source"
Sweet Round 05 E。
idea & solution: Isaunoya & Alex_Wei。
Translated by ChatGPT 5