NC222451. [USACOJan2021P]PaintbyLetters
描述
AAB BBA BBB
can be colored in four strokes as follows:
... ..B AAB AAB AAB ... -> ... -> ... -> BB. -> BBA ... ... ... BBB BBBIt is not possible to produce the end result using less than four strokes.
输入描述
The first line contains N, M, and Q.
The next N lines each contain a string of M uppercase characters representing the desired colors for each row of the canvas.
The next Q lines each contain four space-separated integers x1,y1,x2,y2 representing a candidate subrectangle (1≤x1≤x2≤N, 1≤y1≤y2≤M).
输出描述
For each of the Q candidates, output the answer on a new line.
示例1
输入:
4 8 9 ABBAAAAA ABAAAABA CAADABBA AAAAAAAA 1 1 4 8 3 5 3 8 1 3 2 4 1 4 2 5 1 1 3 3 4 4 4 4 2 6 4 8 3 5 4 6 1 6 3 8
输出:
6 3 2 1 4 1 3 2 2
说明:
The first candidate consists of the entire canvas, which can be painted in six strokes.