Advertisement
Ritam_C

Labyrinth

Jan 6th, 2022
701
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. typedef unsigned long long ull;
  4. #define pb push_back
  5. #define vll vector<ll>
  6. #define vi vector<int>
  7. #define F first
  8. #define S second
  9. #define tests int t; cin >> t; while(t--)
  10. using namespace std;
  11.  
  12. int n, m, r, c, ans = 0; ll x, y;
  13. vector<string> grid;
  14. vector<vi> vis;
  15.  
  16. struct Node {
  17.     ll v, h, left, right;
  18. };
  19.  
  20. int main() {
  21.     ios_base::sync_with_stdio(false);
  22.     cin.tie(NULL); cout.tie(NULL);
  23.     cin >> n >> m >> r >> c >> x >> y;
  24.     grid.resize(n);
  25.     for(string& s : grid) cin >> s;
  26.     vis.assign(n, vi(m, 0));
  27.     deque<Node> q;
  28.     q.push_front({r-1, c-1, 0, 0});
  29.     vis[r-1][c-1] = 1;
  30.     while(!q.empty()) {
  31.         Node t = q.front(); q.pop_front();
  32.         if(t.v > 0 && grid[t.v-1][t.h] == '.' && !vis[t.v-1][t.h]) {
  33.             q.push_front({t.v-1, t.h, t.left, t.right});
  34.             vis[t.v-1][t.h] = 1;
  35.         }
  36.         if(t.v < n-1 && grid[t.v+1][t.h] == '.' && !vis[t.v+1][t.h]) {
  37.             q.push_front({t.v+1, t.h, t.left, t.right});
  38.             vis[t.v+1][t.h] = 1;
  39.         }
  40.         if(t.h < m-1 && grid[t.v][t.h+1] == '.' && !vis[t.v][t.h+1] && t.right < y) {
  41.             q.push_back({t.v, t.h+1, t.left, t.right+1});
  42.             vis[t.v][t.h+1] = 1;
  43.         }
  44.         if(t.h > 0 && grid[t.v][t.h-1] == '.' && !vis[t.v][t.h-1] && t.left < x) {
  45.             q.push_back({t.v, t.h-1, t.left+1, t.right});
  46.             vis[t.v][t.h-1] = 1;
  47.         }
  48.     }
  49.     for(vi v : vis) {
  50.         for(int i : v) ans += i;
  51.     }
  52.     cout << ans;
  53.     return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement