Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<queue>
- #include<cstring>
- using namespace std;
- ifstream fin("pereti.in");
- ofstream fout("pereti.out");
- int di[4]={-1, 0,1, 0};
- int dj[4]={0,1,0,-1};
- int a[115][115];
- int b[115][115];
- queue<pair<int, int> >q;
- int Fill(int i, int j)
- {
- int k,nexti,nextj,nr;
- int zid=0;
- q.push({i,j});
- b[i][j]=-1;
- while(!q.empty())
- {
- i=q.front().first;
- j=q.front().second;
- q.pop();
- nr=16;
- for(k=0;k<4;k++)
- {
- nr/=2;
- nexti=i+di[k];
- nextj=j+dj[k];
- if(b[nexti][nextj]!=-1)
- {
- if((a[i][j] & nr)==0)
- {
- q.push({nexti, nextj});
- b[nexti][nextj]=-1;
- }
- else
- {
- zid++;
- }
- }
- }
- }
- return zid;
- }
- int main()
- {
- int n,m,i,j;
- fin>>n>>m;
- for(i=2;i<=n+1;i++)
- {
- for(j=2;j<=m+1;j++)
- {
- fin>>a[i][j];
- }
- }
- for(j=0;j<=m+3;j++)
- {
- a[0][j]=a[n+3][j]=-1;
- }
- for(i=0;i<=n+3;i++)
- {
- a[i][0]=a[i][m+3]=-1;
- }
- for(j=1;j<=m+1;j++)
- {
- a[1][j]=8;
- a[n+1][j]=2;
- }
- for(i=1;i<=n+1;i++)
- {
- a[i][1]=1;
- a[i][m+1]=4;
- }
- memset(b,0,sizeof(0));
- int pereti;
- pereti=Fill(1,1);
- fout<<pereti;
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement