cswork / OA打开练习工作台

DatabricksOA #21

Longest Common Prefix of Number Pairs

估计中等可在线判题

考点(AI 标注)字典树序列化哈希计数

Given two arrays of positive integers, take one number from each and find the maximum, over all pairs, of the length of the longest common prefix of their decimal representations; if no pair shares a first digit, output 0.

Standard input/output and this site's supplementary ranges follow this problem's description.

输入格式

The first line contains n m (1≤n,m≤50000), followed by two lines giving n and m integers respectively, all in [1,10⁹]. The range of m is a site supplement, following the original limit given for the first array.

输出格式

Output the maximum length of the longest common prefix, as one integer.

样例 1

输入:

6 7
25 288 2655 54546 54 555
2 255 266 244 26 5 54547

输出:

4

样例 2

输入:

6 7
25 288 2655 544 54 555
2 255 266 244 26 5 5444444

输出:

3

样例 3

输入:

2 2
817 99
1999 1909

输出:

0