Josif_tepe

Untitled

Feb 18th, 2026
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4. #include <bits/stdc++.h>
  5. using namespace std;
  6. const int maxn = 255;
  7.  
  8. char mat[maxn][maxn];
  9. int main() {
  10.     int n, m;
  11.     cin >> n >> m;
  12.    
  13.     for(int i = 0; i < n; i++) {
  14.         for(int j = 0; j < m; j++) {
  15.             cin >> mat[i][j];
  16.         }
  17.     }
  18.    
  19.     vector<vector<bool>> visited(n, vector<bool>(m, false));
  20.    
  21.     int di[] = {-1, 1, 0, 0};
  22.     int dj[] = {0, 0, -1, 1};
  23.    
  24.    
  25.     int vkupno_ovci = 0, vkupno_volci = 0;
  26.     for(int i = 0; i < n; i++) {
  27.         for(int j = 0; j < m; j++) {
  28.             if(mat[i][j] != '#' and !visited[i][j]) {
  29.                 queue<int> q;
  30.                 q.push(i);
  31.                 q.push(j);
  32.                
  33.                 visited[i][j] = true;
  34.                
  35.                 int ovci = 0, volci = 0;
  36.                
  37.                 while(!q.empty()) {
  38.                     int ci = q.front();
  39.                     q.pop();
  40.                     int cj = q.front();
  41.                     q.pop();
  42.                    
  43.                     if(mat[ci][cj] == 'o') {
  44.                         ovci++;
  45.                     }
  46.                     if(mat[ci][cj] == 'v') {
  47.                         volci++;
  48.                     }
  49.                    
  50.                     for(int k = 0; k < 4; k++) {
  51.                         int ti = ci + di[k];
  52.                         int tj = cj + dj[k];
  53.                        
  54.                         if(ti >= 0 and ti < n and tj >= 0 and tj < m and !visited[ti][tj] and mat[ti][tj] != '#') {
  55.                             q.push(ti);
  56.                             q.push(tj);
  57.                             visited[ti][tj] = true;
  58.                         }
  59.                     }
  60.                    
  61.                 }
  62.                
  63.                 if(ovci > volci) {
  64.                     vkupno_ovci += ovci;
  65.                 }
  66.                 else {
  67.                     vkupno_volci += volci;
  68.                 }
  69.                
  70.                
  71.                
  72.             }
  73.         }
  74.     }
  75.  
  76.     cout << vkupno_ovci << " " << vkupno_volci << endl;
  77.    
  78.    
  79.    
  80.    
  81.     return 0;
  82. }
  83.  
  84. /*
  85. 5 7
  86. ####..#
  87. S...#.#
  88. .......
  89. #.#.#.E
  90. #######
  91.  
  92.  **/
  93.  
Advertisement
Add Comment
Please, Sign In to add comment