比赛 |
20201031 |
评测结果 |
AAWWWWAAWWA |
题目名称 |
乳草的入侵 |
最终得分 |
45 |
用户昵称 |
数声风笛ovo |
运行时间 |
0.005 s |
代码语言 |
C++ |
内存使用 |
0.98 MiB |
提交时间 |
2020-10-31 23:40:51 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define re register int
#define pp cout<<"qwq"
using namespace std;
const int maxn=1e2+9;
int m,n,x,y,ans=0;
int a[maxn][maxn]={0};
bool b[maxn][maxn]={0};
void dfs(int nx,int ny){
if(nx<=0||nx>n||ny<=0||ny>m) return ;
if(a[nx][ny]||b[nx][ny]) return ;
b[nx][ny]=1;
dfs(nx+1,ny+1);
dfs(nx+1,ny);
dfs(nx+1,ny-1);
dfs(nx-1,ny+1);
dfs(nx-1,ny);
dfs(nx-1,ny-1);
dfs(nx,ny+1);
dfs(nx,ny-1);
}
bool flood(){
for(re i=1;i<=n;i++){
for(re j=1;j<=m;j++){
if(!a[i][j]) return true;
}
}
return false;
}
void week(){
a[x][y]=114514;
while(flood()){
ans++;
for(re i=1;i<=n;i++){
for(re j=1;j<=m;j++){
b[i][j]=0;
}
}
for(re i=1;i<=n;i++){
for(re j=1;j<=m;j++){
if(!a[i][j]){
if(a[i-1][j]==114514||a[i+1][j]==114514||a[i][j-1]==114514||a[i][j+1]==114514||a[i-1][j-1]==114514||a[i-1][j+1]==114514||a[i+1][j-1]==114514||a[i+1][j+1]==114514||a[i+1][j+1]==114514) b[i][j]=1;
}
}
}
for(re i=1;i<=n;i++){
for(re j=1;j<=m;j++){
if(b[i][j]){
a[i][j]=114514;
}
}
}
}
return ;
}
int main(){
freopen("milkweed.in","r",stdin);
freopen("milkweed.out","w",stdout);
scanf("%d%d%d%d",&m,&n,&x,&y);
for(re i=n;i>=1;i--){
string p;
cin>>p;
for(re j=0;j<m;j++){
if(p[j]=='*') a[i][j+1]=1;
else a[i][j+1]=0;
}
}
dfs(x,y);
for(re i=1;i<=n;i++){
for(re j=1;j<=m;j++){
//cout<<a[i][j];
if(!a[i][j]&&!b[i][j]){
printf("-1\n");
return 0;
}
}
//cout<<"\n";
}
week();
printf("%d\n",ans);
return 0;
}