atcoder#ARC154B. [ARC154B] New Place
[ARC154B] New Place
Score : points
Problem Statement
You are given strings and of length consisting of lowercase English letters.
You can repeat the following operation any number of times (possibly zero).
- Erase the first character of and insert the same character at any position of .
Determine whether it is possible to make equal , and if it is possible, find the minimum number of operations needed.
Constraints
- and are strings of length consisting of lowercase English letters.
Input
The input is given from Standard Input in the following format:
Output
If it is impossible to make equal , print -1
. If it is possible, print the minimum number of operations needed.
4
abab
abba
2
You can make equal in two operations, as follows.
- Erase the first character of , and insert that character
a
at the end of , makingbaba
. - Erase the first character of , and insert that character
b
between the -nd and -rd characters of , makingabba
.
It is impossible to make equal in one or fewer operations, so the answer is .
3
arc
cra
2