60分,5,7,8,9wa
查看原帖
60分,5,7,8,9wa
615166
zhouzihang3楼主2023/7/5 20:50
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
int n,m;
int ans=0,xx,yy,st=1,sp=1,sb;
char a[3000][3000];
void dfs(int x,int y,int step){
	if(x-step<=0||y-step<=0||x+step>n||y+step>n) return;
	if(a[x+step][y]==a[x-step][y]){
        st=2*step+1;
        dfs(x,y,step+1);
    }
    return;
}
void nfc(int x,int y,int step){
	if(x-step<=0||y-step<=0||x+step>n||y+step>n) return;
	if(a[x][y+step]==a[x][y-step]){
        sp=2*step+1;
        nfc(x,y,step+1);
    }
    return;
}
int main(){
    cin>>n>>m;
	for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
        }
    }
    while(m--){
        cin>>xx>>yy;
        dfs(xx,yy,1);
        nfc(xx,yy,1);
        sb=max(st,sp);
        cout<<sb<<endl;
        st=1;
        sp=1;
    }
	return 0;
}

60求助

2023/7/5 20:50
加载中...