forked from mpfeifer1/Kattis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbracketmatrix.cpp
58 lines (47 loc) · 1.07 KB
/
bracketmatrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <bits/stdc++.h>
using namespace std;
int n;
bool process(vector<char>& currcol, vector<int>& col) {
sort(col.begin(),col.end());
sort(currcol.begin(),currcol.end());
bool works = true;
for(int i = 0; i < n; i++) {
if(currcol[i] == '(') col[i]++;
else col[i]--;
if(col[i] < 0) works = false;
}
return works;
}
int main() {
cin >> n;
vector<vector<char>> v(n,vector<char>(n));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> v[i][j];
}
}
vector<int> col(n,0);
bool works = true;
for(int i = 0; i < n; i++) {
vector<char> currcol;
for(int j = 0; j < n; j++) {
currcol.push_back(v[j][i]);
}
if(!process(currcol,col)) {
works = false;
break;
}
}
for(int i = 0; i < col.size(); i++) {
if(col[i] != 0) {
works = false;
break;
}
}
if(works) {
cout << "Yes" << endl;
}
else {
cout << "No" << endl;
}
}