Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- using namespace std;
- const int maxn = 1005;
- char mat[maxn][maxn];
- int n, m;
- int main() {
- cin >> n >> m;
- int W;
- cin >> W;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- }
- }
- ;
- vector<vector<int>> cnt(n, vector<int>(m, 0));
- int di[] = {-1, 1, 0, 0};
- int dj[] = {0, 0, -1, 1};
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] == 'C') {
- vector<vector<bool>> visited(n, vector<bool>(m, false));
- int si = i;
- int sj = j;
- queue<int> q;
- q.push(si);
- q.push(sj);
- q.push(0);
- visited[si][sj] = true;
- while(!q.empty()) {
- int ci = q.front();
- q.pop();
- int cj = q.front();
- q.pop();
- int d = q.front();
- q.pop();
- if(d > W) {
- continue;
- }
- if(mat[ci][cj] == '.') {
- cnt[ci][cj]++;
- }
- for(int k = 0; k < 4; k++) {
- int ti = ci + di[k];
- int tj = cj + dj[k];
- if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj] and mat[ti][tj] != '#') {
- q.push(ti);
- q.push(tj);
- q.push(d + 1);
- visited[ti][tj] = true;
- }
- }
- }
- }
- }
- }
- int res = 0, ei, ej;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] == '.') {
- if(res < cnt[i][j]) {
- res = cnt[i][j];
- ei = i + 1;
- ej = j + 1;
- }
- }
- }
- }
- cout << ei << " " << ej << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement