SHARE
TWEET

Untitled

a guest Nov 9th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 2e5+5, INF = 1e9;
  6.  
  7. int main(){
  8.     ios_base::sync_with_stdio(0);
  9.     cin.tie(0); cout.tie(0);
  10.     int n, cnt = 0, i = -1;
  11.     cin >> n;
  12.     vector<vector<char>> m(n,vector<char>(n)), tm;
  13.     set<vector<vector<char>>> s;
  14.     for(int i = 0; i < n; ++i)
  15.         for(int j = 0; j < n; ++j)
  16.             cin >> m[i][j], cnt+=m[i][j]=='*';
  17.     if(cnt==0){ cout << "No\n" << i+1; return 0;}
  18.     tm = m;
  19.     for(i = 0;!s.count(m); ++i){
  20.         s.insert(m);
  21.         cnt = 0;
  22.         for(int i = 0; i < n; ++i){
  23.             for(int j = 0; j < n; ++j){
  24.                 int k = 0;
  25.                 for(int x = -1; x < 2; ++x)
  26.                     for(int y = -1; y < 2; ++y)
  27.                         k+=((x|y)&&i+x>=0&&i+x<n&&j+y>=0&&j+y<n&&m[i+x][j+y]=='*');
  28.                 if(k==3) tm[i][j] = '*';
  29.                 if(k<2||k>3) tm[i][j] = 'x';
  30.                 cnt+=tm[i][j] =='*';
  31.             }
  32.         }
  33.         if(cnt==0){ cout << "No\n" << i+1; return 0;}
  34.         m = tm;
  35.     }
  36.     cout << "Yes\n" << i;
  37.  
  38.     return 0;
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top