Advertisement
radmickey

Untitled

Apr 15th, 2023
665
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. int N, M, xs, ys, x, y;
  6.  
  7. struct point {
  8.     int x;
  9.     int y;
  10.     int l;
  11.     int r;
  12.  
  13.     point(int x_, int y_, int l_, int r_) : x(x_), y(y_), l(l_), r(r_) {}
  14. };
  15.  
  16. bool check_corect(int x, int y, int maxx, int maxy) {
  17.     if (x < 0 || y < 0 || x >= maxx || y >= maxy) {
  18.         return false;
  19.     }
  20.     return true;
  21. }
  22.  
  23. int main() {
  24.     std::vector<std::pair<int, int>> basis_cord = {{1,  0},
  25.                                                    {0,  1},
  26.                                                    {-1, 0},
  27.                                                    {0,  -1}};
  28.  
  29.     std::cin >> N >> M;
  30.     std::cin >> xs >> ys;
  31.     std::cin >> x >> y;
  32.  
  33.     std::vector<std::vector<char>> place(N, std::vector<char>(M, '.'));
  34.  
  35.     for (int i = 0; i < N; i++) {
  36.         for (int j = 0; j < M; j++) {
  37.             std::cin >> place[i][j];
  38.         }
  39.     }
  40.  
  41.     std::queue<point> q;
  42.  
  43.     int ans = 0;
  44.     if (place[xs][ys] == '.') {
  45.         q.push(point(xs, ys, x, y));
  46.         ans++;
  47.         place[xs][ys] = '#';
  48.     }
  49.  
  50.     while (!q.empty()) {
  51.         point node = q.front();
  52.         q.pop();
  53.         for (auto& basis: basis_cord) {
  54.             if (check_corect(node.x + basis.first, node.y + basis.second, N, M)) {
  55.                 if (place[node.x + basis.first][node.y + basis.second] == '.') {
  56.                     int l_c = 0;
  57.                     int r_c = 0;
  58.  
  59.                     if (basis.second == -1) {
  60.                         l_c = -1;
  61.                         if (node.l <= 0) {
  62.                             continue;
  63.                         }
  64.                     }
  65.  
  66.                     if (basis.second == 1) {
  67.                         r_c = -1;
  68.                         if (node.r <= 0) {
  69.                             continue;
  70.                         }
  71.                     }
  72.  
  73.                     q.push(point(node.x + basis.first, node.y + basis.second, node.l + l_c, node.r + r_c));
  74.  
  75.                     place[node.x + basis.first][node.y + basis.second] = '#';
  76.  
  77.                     ans++;
  78.                 }
  79.             }
  80.         }
  81.     }
  82.     std::cout << ans;
  83.  
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement