- js24012 的博客
O1505 【提高】泉水
- @ 2026-3-15 16:15:14
O1505 【提高】泉水
#include <bits/stdc++.h>
using namespace std;
int n,m,p1,p2,g[1005][1005],cnt,v[1005][1005],xx[]={0,0,1,-1},yy[]={1,-1,0,0};
bool check(int nx,int ny){
if(nx<1||ny<1||nx>n||ny>m)return false;
if(v[nx][ny])return 0;
if(g[nx][ny]>g[p1][p2])return 0;
return true;
}
struct stu{int x,y;};
void bfs(int x,int y){
queue <stu> q;
v[x][y]=1;cnt++;
q.push((stu){x,y});
while(!q.empty()){
stu f=q.front();
q.pop();
//v[nx][ny]=1;cnt++;
for(int i=0;i<4;i++){
int nx=f.x+xx[i],ny=f.y+yy[i];
if(check(nx,ny)){
v[nx][ny]=1;cnt++;
q.push((stu){nx,ny});
}
}
}
}
int main()
{
cin>>n>>m>>p1>>p2;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)cin>>g[i][j];
bfs(p1,p2);
cout<<cnt;
return 0;
}