Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- int N, M, xs, ys, x, y;
- struct point {
- int x;
- int y;
- int l;
- int r;
- point(int x_, int y_, int l_, int r_) : x(x_), y(y_), l(l_), r(r_) {}
- };
- bool check_corect(int x, int y, int maxx, int maxy) {
- if (x < 0 || y < 0 || x >= maxx || y >= maxy) {
- return false;
- }
- return true;
- }
- int main() {
- std::vector<std::pair<int, int>> basis_cord = {{1, 0},
- {0, 1},
- {-1, 0},
- {0, -1}};
- std::cin >> N >> M;
- std::cin >> xs >> ys;
- std::cin >> x >> y;
- std::vector<std::vector<char>> place(N, std::vector<char>(M, '.'));
- for (int i = 0; i < N; i++) {
- for (int j = 0; j < M; j++) {
- std::cin >> place[i][j];
- }
- }
- std::queue<point> q;
- int ans = 0;
- if (place[xs][ys] == '.') {
- q.push(point(xs, ys, x, y));
- ans++;
- place[xs][ys] = '#';
- }
- while (!q.empty()) {
- point node = q.front();
- q.pop();
- for (auto& basis: basis_cord) {
- if (check_corect(node.x + basis.first, node.y + basis.second, N, M)) {
- if (place[node.x + basis.first][node.y + basis.second] == '.') {
- int l_c = 0;
- int r_c = 0;
- if (basis.second == -1) {
- l_c = -1;
- if (node.l <= 0) {
- continue;
- }
- }
- if (basis.second == 1) {
- r_c = -1;
- if (node.r <= 0) {
- continue;
- }
- }
- q.push(point(node.x + basis.first, node.y + basis.second, node.l + l_c, node.r + r_c));
- place[node.x + basis.first][node.y + basis.second] = '#';
- ans++;
- }
- }
- }
- }
- std::cout << ans;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement