#K7906. Transforming Strings with Subsequence Operations

    ID: 35224 Type: Default 1000ms 256MiB

Transforming Strings with Subsequence Operations

Transforming Strings with Subsequence Operations

Given two strings (S) and (T), determine the minimum number of operations required to form (T) by repeatedly appending a subsequence of (S). In one operation, you can select any subsequence (not necessarily contiguous) from (S) and append it to the current string. If it is impossible to form (T) in this manner, output (-1).

For example, if (S = "abc") and (T = "abcbc"), you can form (T) in 2 operations. This problem requires a good understanding of greedy algorithms and subsequence properties.

inputFormat

The input consists of two lines. The first line contains the string (S) and the second line contains the string (T). Both strings consist of lowercase English letters.

outputFormat

Output a single integer denoting the minimum number of operations needed to form (T) from (S) by appending subsequences. If it is impossible, output (-1).## sample

abc
abcbc
2