Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <string>
- #include <queue>
- #include <map>
- #include <set>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <unordered_map>
- #include <unordered_set>
- using namespace std;
- #define ll long long
- #define nl endl
- #define cy cout << "YES\n"
- #define cn cout << "NO\n"
- #define sz s.size()
- #define allv v.begin(), v.end()
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- vector<vector<char>> grid;
- vector<vector<bool>> vis;
- int rows, cols, l, f, cnt = 0;
- bool valid(int r, int c)
- {
- return r < rows && c < cols && r >= 0 && c >= 0;
- }
- void find_path(int r, int c)
- {
- if (!valid(r, c) || grid[r][c] == '*' || vis[r][c] == 1)
- return;
- vis[r][c] = 1;
- cnt++;
- find_path(r - 1, c);
- find_path(r + 1, c);
- find_path(r, c - 1);
- find_path(r, c + 1);
- }
- void solve()
- {
- cin >> rows >> cols;
- vis.assign(rows, vector<bool>(cols));
- grid.assign(rows, vector<char>(cols));
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- cin >> grid[i][j];
- }
- }
- cin >> l >> f;
- find_path(--l, --f);
- cout << cnt << nl;
- }
- int main()
- {
- sherry();
- ll t = 1;
- // cin >> t;
- while (t--)
- {
- solve();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement