#P15854. [蓝桥杯第二届国际赛] 基因子序列
[蓝桥杯第二届国际赛] 基因子序列
Problem Description
A biological gene is made up of different bases, usually denoted by A, T, G, and C. A gene can be represented as a sequence of bases in order, for example, ATCACAGGT.
Xiaoming has recently been paying attention to a special base sequence (and is also composed of A, T, G, and C). He found that if, in a gene, we can extract some bases in their order of appearance and make them exactly equal to , then the gene may have some property. For example, when , we can extract the nd, rd, and th bases from the gene ATCACAGGT to match , but we cannot extract a part of the gene CGT to match .
Of course, the extraction positions can be varied. For instance, we can extract the nd, th, and th bases from the gene ATCACAGGT to match . Xiaoming wants to know: among all ways that can make them equal, what is the minimum possible index of the last extracted base in the gene.
Input Format
The first line contains a string , representing the given base sequence.
The second line contains a string , representing the given gene.
Output Format
If no valid extraction method can be found, output . Otherwise, output the index of the last extracted base in the gene when they are equal.
TCG
ATCACAGGT
7
Hint
Sample Explanation
This problem asks for the minimum answer. If you output , it is incorrect.
Constraints
For of the test cases, the lengths of both strings do not exceed .
For all test cases, the lengths of both strings do not exceed . The characters that appear are only A, T, C, and G.
Translated by ChatGPT 5