forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE.cpp
More file actions
67 lines (51 loc) · 1.11 KB
/
E.cpp
File metadata and controls
67 lines (51 loc) · 1.11 KB
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
59
60
61
62
63
64
65
66
67
#include<bits/stdc++.h>
using namespace std;
int f[1005], g[1005], cnt[1005], n;
int cmp(int i, int j) {
if (cnt[i] == cnt[j]) return (i < j);
return cnt[i] < cnt[j];
}
int main() {
string s[1005];
vector<int> v;
freopen("relations.in", "r", stdin);
freopen("relations.out", "w", stdout);
cin >> n;
for(int i=0; i<n; i++) {
cin >> s[i];
v.push_back(i);
cnt[i] = 0;
for(int j=0; j<n; j++) {
if (s[i][j] == '1') {
cnt[i]++;
}
}
}
sort(v.begin(), v.end(), cmp);
bool correct = true;
for(int i=0; i<n-1; i++) {
int x = v[i];
int y = v[i+1];
for(int j=0; j<n; j++)
if (s[x][j] > s[y][j]) {
correct = false;
break;
}
if(!correct) break;
}
for(int i=0; i<n; i++) f[i] = n - cnt[i];
for(int i=0; i<n; i++) {
for(int j=0; j<n; j++) {
if (s[i][j] == '1') g[j] = max(g[j], f[i]);
}
}
if (correct) {
cout << "YES" << endl;
for(int i=0; i<n; i++) cout << f[i] << " ";
cout << endl;
for(int i=0; i<n; i++) cout << g[i] << " ";
cout << endl;
} else {
cout << "NO" << endl;
}
}