Advertisement
Josif_tepe

Untitled

Jun 8th, 2024
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.   int n, m;
  9.   cin >> n >> m;
  10.   int W;
  11.   cin >> W;
  12.  
  13.   char mat[n][m];
  14.   for(int i = 0; i < n; i++) {
  15.     for(int j = 0; j < m; j++) {
  16.       cin >> mat[i][j];
  17.     }
  18.   }  
  19.  
  20.   int di[] = {-1, 1, 0, 0};
  21.   int dj[] = {0, 0, -1, 1};
  22.   vector<vector<int>> cnt(n, vector<int>(m, 0));
  23.   for(int i = 0; i < n; i++) {
  24.     for(int j = 0; j < m; j++) {
  25.       if(mat[i][j] == 'C') {
  26.         queue<int> q;
  27.         q.push(i);
  28.         q.push(j);
  29.         q.push(0);
  30.         vector<vector<bool>> visited(n, vector<bool>(m, false));
  31.         visited[i][j] = true;
  32.         while(!q.empty()) {
  33.           int ci = q.front();
  34.           q.pop();
  35.           int cj = q.front();
  36.           q.pop();
  37.           int cekor = q.front();
  38.           q.pop();  
  39.           cnt[ci][cj]++;
  40.  
  41.           for(int k = 0; k < 4; k++) {
  42.             int ti = ci + di[k];
  43.             int tj = cj + dj[k];
  44.             if(ti >= 0 and ti < n and tj >= 0 and tj < m and mat[ti][tj] != '#' and !visited[ti][tj]) {
  45.                 if(cekor + 1 <= W) {
  46.                     q.push(ti);
  47.                     q.push(tj);
  48.                     q.push(cekor + 1);
  49.                     visited[ti][tj] = true;
  50.                 }
  51.             }
  52.           }
  53.  
  54.  
  55.         }
  56.       }
  57.     }
  58.   }
  59.   int res = 0;
  60.   int ri = 0, rj = 0;
  61.   for(int i = 0; i < n; i++) {
  62.     for(int j = 0; j < m; j++) {
  63.       if(res < cnt[i][j] and mat[i][j] == '.') {
  64.         res = cnt[i][j];
  65.         ri = i;
  66.         rj = j;
  67.       }
  68.     }
  69.    
  70.   }
  71.   cout << ri + 1 << " " << rj + 1<< endl;
  72.     return 0;
  73. }
  74.  /*
  75. CX..
  76. C...
  77.  
  78. K = 2
  79.  
  80.  
  81.  **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement