All submissions for this problem are available.
After completing the preliminary tests, Full Metal now faces his final exam.
Captain Mustang gives him an n*m grid of letters. He defined distance between two rows of the grid as the largest absolute difference between letters in the same column.
Full Metal is assigned to mark all the rows. The cost of marking the first row of his choice is zero. Thereafter the cost of marking each row is equal to the distance of the row(being marked) from any one of the previously marked rows.
Help Full Metal to determine the least value of the largest cost of marking a row.
First line contains dimensions of grid n and m.
Next n lines contain strings of m characters each.
Output the least value of the largest cost of marking a row.
2 ≤ n ≤ 2000
1 ≤ m ≤ 25
3 3 abc elm xet
One alternative for Full Metal is to mark 1st row first then mark second row and then third.
Cost of marking 2nd row will be ('l'-'b') = 10 and cost of marking 3rd row will be('x'-'e') = 19
|Time Limit:||1 - 1.5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, CS2|
Fetching successful submissions
If you are still having problems, see a sample solution here.