luogu#P4888. 三去矩阵

三去矩阵

Problem Description

Now Little Y has an l×ll \times l square letter matrix. He wants to make qq queries. For each query, find the maximum length of a palindrome string centered at (xi,yi)(x_i, y_i) that lies on a single horizontal or vertical line.

Input Format

The first line contains two integers l,ql, q, representing the side length of the matrix and the number of queries.

The next ll lines each contain ll letters, representing the letters in the matrix.

The next qq lines each contain two integers xi,yix_i, y_i, representing the ii-th query: ask for the maximum length of a palindrome centered at (xi,yi)(x_i, y_i) that lies on a single straight line in the matrix.

Output Format

Output qq lines. The ii-th line should be the answer to the ii-th query.

5 5
abcba
bcdcb
cdedc
bcdcb
abcba
1 1
1 2
1 3
2 3
3 3
1
1
5
5
5

Hint

For 20%20\% of the testdata, 1l21 \le l \le 2.

Another 20%20\% of the testdata has q=1q = 1.

Another 20%20\% of the testdata has a letter matrix that is centrally symmetric, vertically symmetric, horizontally symmetric, and diagonally symmetric.

For 100%100\% of the testdata, 1l,q20001 \le l, q \le 2000, and the letters are lowercase only.

Translated by ChatGPT 5