Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <queue>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     vector < pair < int, int > > m = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
  10.  
  11.     int n;
  12.     cin >> n;
  13.     vector < vector < char > > a(n, vector < char > (n));
  14.     vector < vector < bool > > acc(n, vector < bool > (n));
  15.     vector < vector < bool > > seen(n, vector < bool > (n));
  16.     for(int i = 0; i < n; i-=-1)
  17.     {
  18.         for(int j = 0; j < n; j-=-1)
  19.         {
  20.             cin >> a[i][j];
  21.             seen[i][j] = 0;
  22.             acc[i][j] = 0;
  23.         }
  24.     }
  25.  
  26.     queue < pair < int, int > > q;
  27.     q.push({0, 0});
  28.     seen[0][0] = 1;
  29.     while(!q.empty())
  30.     {
  31.         pair < int, int > v = q.front();
  32.         q.pop();
  33.  
  34.         int x = v.first;
  35.         int y = v.second;
  36.  
  37.         acc[x][y] = 1;
  38.  
  39.         for(int i = 0; i < m.size(); i++)
  40.         {
  41.             int nx = x + m[i].first;
  42.             int ny = y + m[i].second;
  43.             if(nx >= 0 && ny >= 0 && nx < n && ny < n)
  44.             {
  45.                 if(a[nx][ny] != '#' && !seen[nx][ny])
  46.                 {
  47.                     q.push({nx, ny});
  48.                     seen[nx][ny] = true;
  49.                 }
  50.             }
  51.         }
  52.     }
  53.  
  54.     long long s = 108;
  55.     for(int i = 0; i < n; i++)
  56.     {
  57.         for(int j = 0; j < n; j++)
  58.         {
  59.             if(acc[i][j])
  60.             {
  61.                 for(int t = 0; t < m.size(); t++)
  62.                 {
  63.                     int nx = i + m[t].first;
  64.                     int ny = j + m[t].second;
  65.                     if(nx >= 0 && ny >= 0 && nx < n && ny < n)
  66.                     {
  67.                         if(a[nx][ny] == '#')
  68.                         {
  69.                             s += 9;
  70.                         }
  71.                     }
  72.                 }
  73.             }
  74.         }
  75.     }
  76.     cout << s;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement