artemgf

Разрезание квадрата

Jan 11th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.65 KB | None | 0 0
  1. #define _USE_MATH_DEFINES
  2. #include <iostream>
  3. #include <string>
  4. #include <map>
  5. #include <set>
  6. #include <algorithm>
  7. #include <vector>
  8. #include <stdio.h>
  9. #include <cmath>
  10. #include <math.h>
  11. #include <queue>
  12. #include <stack>
  13. #include <climits>
  14. #include <deque>
  15. #include <ctime>
  16.  
  17. using namespace std;
  18.  
  19. typedef long long ll;
  20. typedef unsigned long long ull;
  21. typedef unsigned int ui;
  22.  
  23. #define mh() make_heap()
  24. #define poph() pop_heap()
  25. #define pushh() push_heap()
  26. #define sor(n) n.begin(), n.end()
  27. #define mp make_pair
  28. #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
  29. #define p(T) pair<T,T>
  30. #define znac(l) abs(l)/l
  31. const ll ok = ll(1e9 + 7);
  32. short str[1001][1001];
  33. int main()
  34. {
  35.     //files;
  36.     int n;
  37.     cin >> n;
  38.  
  39.     for (int i = 1; i <= n; i++)
  40.     {
  41.         string s;
  42.         cin >> s;
  43.         for (int j = 1; j <= n; j++)
  44.         {
  45.             str[i][j] = s[j - 1] - '0';
  46.         }
  47.     }
  48.  
  49.     ll last = -1;
  50.     bool bad = 0;
  51.     bool exit = 0;
  52.     for (int x = 1; x <= n; x++)
  53.     {
  54.         last = str[x][1];
  55.         bad = 0;
  56.         for (int y = 1; y <= n; y++)
  57.         {
  58.             if (str[x][y] != last)
  59.             {
  60.                 if (!bad)
  61.                     bad = 1;
  62.                 else
  63.                 {
  64.                     exit = 1;
  65.                     break;
  66.                 }
  67.             }
  68.             last = str[x][y];
  69.         }
  70.         if (exit)
  71.             break;
  72.     }
  73.     if (!exit)
  74.     {
  75.         cout <<"Yes";
  76.         return 0;
  77.     }
  78.  
  79.     bad = 0;
  80.     exit = 0;
  81.     for (int y = 1; y <= n; y++)
  82.     {
  83.         last = str[1][y];
  84.         bad = 0;
  85.         for (int x = 1; x <= n; x++)
  86.         {
  87.             if (str[x][y] != last)
  88.             {
  89.                 if (!bad)
  90.                     bad = 1;
  91.                 else
  92.                 {
  93.                     exit = 1;
  94.                     break;
  95.                 }
  96.             }
  97.             last = str[x][y];
  98.         }
  99.         if (exit)
  100.             break;
  101.     }
  102.  
  103.     if (!exit)
  104.     {
  105.         cout << "Yes";
  106.     }
  107.     else
  108.         cout << "No";
  109.  
  110.     return 0;
  111. }
Advertisement
Add Comment
Please, Sign In to add comment