Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- using namespace std;
- int main()
- {
- int n, m;
- cin >> n >> m;
- int W;
- cin >> W;
- char mat[n][m];
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- cin >> mat[i][j];
- }
- }
- int di[] = {-1, 1, 0, 0};
- int dj[] = {0, 0, -1, 1};
- vector<vector<int>> cnt(n, vector<int>(m, 0));
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(mat[i][j] == 'C') {
- queue<int> q;
- q.push(i);
- q.push(j);
- q.push(0);
- vector<vector<bool>> visited(n, vector<bool>(m, false));
- visited[i][j] = true;
- while(!q.empty()) {
- int ci = q.front();
- q.pop();
- int cj = q.front();
- q.pop();
- int cekor = q.front();
- q.pop();
- 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 mat[ti][tj] != '#' and !visited[ti][tj]) {
- if(cekor + 1 <= W) {
- q.push(ti);
- q.push(tj);
- q.push(cekor + 1);
- visited[ti][tj] = true;
- }
- }
- }
- }
- }
- }
- }
- int res = 0;
- int ri = 0, rj = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j < m; j++) {
- if(res < cnt[i][j] and mat[i][j] == '.') {
- res = cnt[i][j];
- ri = i;
- rj = j;
- }
- }
- }
- cout << ri + 1 << " " << rj + 1<< endl;
- return 0;
- }
- /*
- CX..
- C...
- K = 2
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement