原题链接(洛谷):https://www.luogu.com.cn/problem/P4888
题解(C++):
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2048;
int l, q, x, y;
char c[N][N];
signed main() {
cin >> l >> q;
for (int i = 1; i <= l; i++) {
for (int j = 1; j <= l; j++) {
cin >> c[i][j];
}
}
while (q--) {
cin >> x >> y;
int ans = 1;
for (int i = y - 1, j = y + 1; 1 <= i && j <= l; i--, j++)
if (c[x][i] == c[x][j])
ans = max(ans, j - i + 1);
else break;
for (int i = x - 1, j = x + 1; 1 <= i && j <= l; i--, j++)
if (c[i][y] == c[j][y])
ans = max(ans, j - i + 1);
else break;
cout<<ans<<endl;
}
}
没有回复内容