Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main()
- {
- vector < pair < int, int > > m = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
- int n;
- cin >> n;
- vector < vector < char > > a(n, vector < char > (n));
- vector < vector < bool > > acc(n, vector < bool > (n));
- vector < vector < bool > > seen(n, vector < bool > (n));
- for(int i = 0; i < n; i-=-1)
- {
- for(int j = 0; j < n; j-=-1)
- {
- cin >> a[i][j];
- seen[i][j] = 0;
- acc[i][j] = 0;
- }
- }
- queue < pair < int, int > > q;
- q.push({0, 0});
- seen[0][0] = 1;
- while(!q.empty())
- {
- pair < int, int > v = q.front();
- q.pop();
- int x = v.first;
- int y = v.second;
- acc[x][y] = 1;
- for(int i = 0; i < m.size(); i++)
- {
- int nx = x + m[i].first;
- int ny = y + m[i].second;
- if(nx >= 0 && ny >= 0 && nx < n && ny < n)
- {
- if(a[nx][ny] != '#' && !seen[nx][ny])
- {
- q.push({nx, ny});
- seen[nx][ny] = true;
- }
- }
- }
- }
- long long s = 108;
- for(int i = 0; i < n; i++)
- {
- for(int j = 0; j < n; j++)
- {
- if(acc[i][j])
- {
- for(int t = 0; t < m.size(); t++)
- {
- int nx = i + m[t].first;
- int ny = j + m[t].second;
- if(nx >= 0 && ny >= 0 && nx < n && ny < n)
- {
- if(a[nx][ny] == '#')
- {
- s += 9;
- }
- }
- }
- }
- }
- }
- cout << s;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement