#P10992. [蓝桥杯 2023 国 Python A] 最长同类子串

[蓝桥杯 2023 国 Python A] 最长同类子串

Problem Description

For two strings A,BA, B of the same length, if for any i,ji, j, the two conditions Ai=AjA_i = A_j and Bi=BjB_i = B_j are either both true or both false at the same time, then we call A,BA, B a pair of same-type strings. For example, aabab and xxkxk are a pair of same-type strings, while abcde and abcdd are not.

Given S,TS, T, find the largest possible kk such that S,TS, T each contain a substring of length kk, denoted S,TS', T', and S,TS', T' are a pair of same-type strings.

Input Format

The input consists of two lines. Each line contains a string, representing SS and TT.

Output Format

Output one line containing an integer kk, representing the answer.

aaaba
yxyy

3

Hint

For 40%40\% of the testdata, S,T500|S|, |T| \le 500.

For 50%50\% of the testdata, S,T2000|S|, |T| \le 2000.

For all testdata, 1S,T1051 \le |S|, |T| \le 10^5, and S,TS, T contain only lowercase English letters.

Translated by ChatGPT 5