chenyanhui @ 2024-10-06 16:40:38
#include<bits/stdc++.h>
using namespace std
const int N=1145;
int n,x,y,m,z=1;
char a[N][N];
int b[N][N];
bool c[N][N];
int xx[4]= {0,0,1,-1};
int yy[4]= {1,-1,0,0};
struct inf {
int x,y;
};
void bfs(int x,int y) {
long long k=1;
queue<inf>q;
vector<inf> v;
v.push_back({x,y});
q.push({x,y});
c[x][y]=1;
while(!q.empty()) {
inf t=q.front();
q.pop
for(int i=0; i<4; i++) {
int nx=t.x+xx[i];
int ny=t.y+yy[i];
if(nx>0&&nx<=n&&ny>0&&ny<=n&&a[nx][ny]!=a[t.x][t.y]&&c[nx][ny]==0) {
c[nx][ny]=1;
k++;
v.push_back({nx,ny});
q.push({nx,ny});
}
}
}
for(auto i:v){
b[i.x][i.y]=k;
}
}
int main() {
cin>>n>>m;
for(int i=1;i<=n;i++) {
for(int j=1;j<=n;j++) {
cin>>a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(b[i][j]==0){
bfs(i,j);
}
}
}
for(int i=1;i<=m;i++){
cin>>x>>y;
cout<<b[x][y]<<endl;
}
return 0;
}
by Scez @ 2024-10-06 16:41:11
?
by liu201207 @ 2024-10-06 16:42:31
该错了,就好了
by chenyanhui @ 2024-10-06 16:43:06
@Scez 没明白
by smart_stupid @ 2024-10-06 16:43:16
using namespace std;
q.pop
两个没打分号
by Grammar__hbw @ 2024-10-06 16:43:57
@chenyanhui 把return 0
改成return 1
就行了
(洛谷会自动对返回值模256,所以return 998244352
依然AC)
by Scez @ 2024-10-06 16:46:27
@chenyanhui 什么叫AC了怎么办)
by chenyanhui @ 2024-10-06 16:47:56
@Scez 没明白为什么