Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #define NMAX 2001
- #define ll long long
- #define MOD (int)(1e9 + 7)
- #include <bits/stdc++.h>
- using namespace std;
- ifstream f ("01A.in");
- ofstream g ("01A.out");
- struct hash_pair {
- template <class T1, class T2>
- size_t operator()(const pair<T1, T2>& p) const
- {
- auto hash1 = hash<T1>{}(p.first);
- auto hash2 = hash<T2>{}(p.second);
- if (hash1 != hash2) {
- return hash1 ^ hash2;
- }
- // If hash1 == hash2, their XOR is zero.
- return hash1;
- }
- };
- struct gnome {
- int x, y, left_a, left_b;
- };
- ll ans = 0;
- int T;
- int N, M;
- int x,y;
- int a,b;
- bool viz[NMAX][NMAX];
- int m[NMAX][NMAX];
- char ch;
- const vector<int> dx {-1, 1, 0, 0};
- const vector<int> dy {0, 0, -1, 1};
- //jos, sus, st., dr.
- bool valid (int i, int j) {
- return (i >= 1 && i <= N && j >= 1 && j <= M && m[i][j] != -1);
- }
- int main() { // O(N*M) Lee
- cin >> N >> M;
- cin >> x >> y;
- viz[x][y] = true;
- cin >> b >> a;
- for (int i = 1; i <= N; ++i)
- for (int j = 1; j <= M; ++j)
- {
- cin >> ch;
- if (ch == '_')
- m[i][j] = 0;
- else
- m[i][j] = -1;
- }
- queue<gnome> Q;
- Q.push({x, y, a, b});
- while (!Q.empty()) {
- gnome G = Q.front();
- Q.pop();
- for (int i = 0; i < 2; ++i) //sus & jos
- {
- int xx = G.x + dx[i];
- int yy = G.y + dy[i];
- if (valid(xx, yy) && !viz[xx][yy])
- {
- viz[xx][yy] = true;
- Q.push({xx, yy, G.left_a, G.left_b});
- }
- }
- // st.
- int xx = G.x + dx[2];
- int yy = G.y + dy[2];
- if (valid(xx, yy) && !viz[xx][yy] && G.left_b > 0)
- {
- viz[xx][yy] = true;
- Q.push({xx, yy, G.left_a, G.left_b - 1});
- }
- //dr.
- xx = G.x + dx[3];
- yy = G.y + dy[3];
- if (valid(xx, yy) && !viz[xx][yy] && G.left_a > 0)
- {
- viz[xx][yy] = true;
- Q.push({xx, yy, G.left_a - 1, G.left_b});
- }
- }
- for (int i = 1; i <= N; ++i)
- for (int j = 1; j <= M; ++j)
- if (viz[i][j])
- {
- g << i << ' ' << j << '\n';
- ans ++;
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement