Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<queue>
- #include <fstream>
- using namespace std;
- int main()
- {
- int n,m;
- cin>>n>>m;
- int w;
- cin>>w;
- char mat[n][m];
- pair<int,int>p[n*m + 1];
- int brojac=0;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- cin>>mat[i][j];
- if(mat[i][j]=='C')
- {
- p[brojac].first=i;
- p[brojac].second=j;
- brojac++;
- }
- }
- }
- bool visited[n][m];
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- visited[i][j]=false;
- }
- }
- int preseci[n][m];
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- preseci[i][j]=0;
- }
- }
- queue<int>q;
- int di[]={-1,1,0,0};
- int dj[]={0,0,-1,1};
- for(int i=0;i<brojac;i++)
- {
- q.push(p[i].first);
- q.push(p[i].second);
- q.push(0);
- visited[p[i].first][p[i].second]=true;
- while(!q.empty())
- {
- int ci=q.front();
- q.pop();
- int cj=q.front();
- q.pop();
- int br=q.front();
- q.pop();
- for(int k=0;k<4;k++)
- {
- int ti=ci+di[k];
- int tj=cj+dj[k];
- if(ti>=0 && ti<n && tj>=0 && tj<m && mat[ti][tj]!='#' && !visited[ti][tj] && br+1<=w)
- {
- preseci[ti][tj]++;
- q.push(ti);
- q.push(tj);
- visited[ti][tj]=true;
- q.push(br+1);
- }
- }
- }
- for(int r=0;r<n;r++)
- {
- for(int j=0;j<m;j++)
- {
- visited[r][j]=false;
- }
- }
- }
- int maks=-2e9;
- int maks_i;
- int maks_j;
- for(int i=0;i<n;i++)
- {
- for(int j=0;j<m;j++)
- {
- if(preseci[i][j]>maks and mat[i][j] == '.')
- {
- maks=preseci[i][j];
- maks_i=i;
- maks_j=j;
- }
- }
- }
- cout<<maks_i+1<<" "<<maks_j+1;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement