P28061 [洛谷] 「MYOI-R3」String
普及-
题目描述

Problem Description

Given strings \( s \) and \( t \).

You need to delete some characters from \( s \) and \( t \) and rearrange them to make \( s = t \).

What is the maximum length of \( s \) after the operation?

Input Format

The first line contains a string \( s \).

The second line contains a string \( t \).

Output Format

A single line containing an integer, representing the maximum length of \( s \) after the operation.

Sample Input and Output

Sample Input #1

abc
bc

Sample Output #1

2

Sample Input #2

aaaaa
bbbbb

Sample Output #2

0

Notes

In the first example, delete a and keep bc.

At this point, \( |s| = 2 \), which can be proven to be the optimal solution.

In the second example, delete aaaaa and leave an empty string.
Delete bbbbb and leave an empty string.

At this point, \( |s| = 0 \), which can be proven to be the optimal solution.

This problem uses batched testing.

Let \( n = \max(|s|, |t|) \).

Subtask \( n \le \) Special Conditions Total Score
1 10 None 25
2 \( 10^5 \) A 25
3 \( 10^5 \) B 25
4 \( 10^5 \) None 25

For 100% of the data, \( 1 \le |s|, |t| \le 10^5 \), and both strings consist of lowercase letters.

Special Condition A: \( s \) is a permutation of a to z.

Special Condition B: \( s_i, t_i \in \{ \text{a}, \text{b} \} \).

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
abc bc
样例输出
2