Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- typedef long long ll;
- typedef unsigned long long ull;
- #define pb push_back
- #define vll vector<ll>
- #define vi vector<int>
- #define F first
- #define S second
- #define tests int t; cin >> t; while(t--)
- using namespace std;
- int n, m, r, c, ans = 0; ll x, y;
- vector<string> grid;
- vector<vi> vis;
- struct Node {
- ll v, h, left, right;
- };
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- cin >> n >> m >> r >> c >> x >> y;
- grid.resize(n);
- for(string& s : grid) cin >> s;
- vis.assign(n, vi(m, 0));
- deque<Node> q;
- q.push_front({r-1, c-1, 0, 0});
- vis[r-1][c-1] = 1;
- while(!q.empty()) {
- Node t = q.front(); q.pop_front();
- if(t.v > 0 && grid[t.v-1][t.h] == '.' && !vis[t.v-1][t.h]) {
- q.push_front({t.v-1, t.h, t.left, t.right});
- vis[t.v-1][t.h] = 1;
- }
- if(t.v < n-1 && grid[t.v+1][t.h] == '.' && !vis[t.v+1][t.h]) {
- q.push_front({t.v+1, t.h, t.left, t.right});
- vis[t.v+1][t.h] = 1;
- }
- if(t.h < m-1 && grid[t.v][t.h+1] == '.' && !vis[t.v][t.h+1] && t.right < y) {
- q.push_back({t.v, t.h+1, t.left, t.right+1});
- vis[t.v][t.h+1] = 1;
- }
- if(t.h > 0 && grid[t.v][t.h-1] == '.' && !vis[t.v][t.h-1] && t.left < x) {
- q.push_back({t.v, t.h-1, t.left+1, t.right});
- vis[t.v][t.h-1] = 1;
- }
- }
- for(vi v : vis) {
- for(int i : v) ans += i;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement