luogu#P10270. 好奇心宝贝
好奇心宝贝
Background
Roads are made by people’s own hands.
Wine and bread are gained through work.
Tiny new sprouts stretch out their leaves,
Fighting off sleepiness among piles of potions.
A bit more, just a bit more time,
To read the next page of the book.
Problem Description
You are given an matrix, where each position is a lowercase letter.
Define the string of a path as the string formed by concatenating the characters on the path in order.
Please find two paths from to , where you may only move down or right, to minimize the length of the longest common prefix of the two path strings.
Input Format
The first line contains two numbers .
The next lines each contain characters, describing the whole matrix.
Output Format
Output one number, which is the minimum possible length of the longest common prefix.
3 3
abe
bcx
exy
2
Hint
Explanation of Sample 1
The two chosen paths are:
-
$(1,1)\rightarrow (1,2)\rightarrow (1,3)\rightarrow (2,3)\rightarrow (3,3):$
abexy. -
$(1,1)\rightarrow (1,2)\rightarrow (2,2)\rightarrow (2,3)\rightarrow (3,3):$
abcxy.
Their longest common prefix has length . It can be proven that there is no better solution.
Constraints and Notes
For of the testdata, .
For of the testdata, .
For the other of the testdata, the matrix is randomly generated and contains only letters a,b.
For of the testdata, , and the input contains only integers and lowercase letters.
Translated by ChatGPT 5