#P10069. [CCO 2023] Flip it and Stick it
[CCO 2023] Flip it and Stick it
Problem Description
Finn is playing a game called “Flip it and Stick it”, abbreviated as FiSi. FiSi is a single-player game played on two strings and consisting of 0s and 1s. Finn can perform the following type of operation:
Choose a substring of and reverse it, then stick the parts of the string back together in the original order to form a new string . For example, Finn can take the string , choose the substring starting from position 2 (the string is indexed from ), and create the string in one operation.
If does not contain as a substring, Finn wins the game. Your task is to help Finn determine the length of the shortest sequence of operations needed to win the game, or tell him that the game cannot be won.
Input Format
The first line contains a string .
The second line contains a string .
Output Format
Output one line containing an integer: the minimum number of operations needed to win if it is possible, otherwise output .
100110
10
2
000
00
-1
Hint
Sample Explanation 1
Finn starts from the string . He cannot make not be a substring with one operation, but he can do it in two operations.
For example, his first operation can be to reverse the substring from position 4 to position 6 (), obtaining . Then, his second operation can be to reverse the substring from position 1 to position 4 (), obtaining , which does not contain as a substring.
Sample Explanation 2
No matter how many operations Finn performs, the string will always be a substring of .
For all testdata, , .
Let .
| Subtask ID | Score | Constraint on |
|---|---|---|
| 1 | 4 | |
| 2 | 12 | |
| 3 | 16 | |
| 4 | 20 | |
| 5 | ||
| 6 | 28 |
Translated by ChatGPT 5