Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef unsigned int ui;
- #define mh() make_heap()
- #define poph() pop_heap()
- #define pushh() push_heap()
- #define sor(n) n.begin(), n.end()
- #define mp make_pair
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define p(T) pair<T,T>
- #define znac(l) abs(l)/l
- const ll ok = ll(1e9 + 7);
- short str[1001][1001];
- int main()
- {
- //files;
- int n;
- cin >> n;
- for (int i = 1; i <= n; i++)
- {
- string s;
- cin >> s;
- for (int j = 1; j <= n; j++)
- {
- str[i][j] = s[j - 1] - '0';
- }
- }
- ll last = -1;
- bool bad = 0;
- bool exit = 0;
- for (int x = 1; x <= n; x++)
- {
- last = str[x][1];
- bad = 0;
- for (int y = 1; y <= n; y++)
- {
- if (str[x][y] != last)
- {
- if (!bad)
- bad = 1;
- else
- {
- exit = 1;
- break;
- }
- }
- last = str[x][y];
- }
- if (exit)
- break;
- }
- if (!exit)
- {
- cout <<"Yes";
- return 0;
- }
- bad = 0;
- exit = 0;
- for (int y = 1; y <= n; y++)
- {
- last = str[1][y];
- bad = 0;
- for (int x = 1; x <= n; x++)
- {
- if (str[x][y] != last)
- {
- if (!bad)
- bad = 1;
- else
- {
- exit = 1;
- break;
- }
- }
- last = str[x][y];
- }
- if (exit)
- break;
- }
- if (!exit)
- {
- cout << "Yes";
- }
- else
- cout << "No";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment