-
Notifications
You must be signed in to change notification settings - Fork 1
/
uva1592-b.cpp
70 lines (63 loc) · 1.59 KB
/
uva1592-b.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
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <map>
#include <vector>
using namespace std;
typedef pair<int, int> pii;
const int N = 10010, M = 20;
int n, m;
// 这个超慢的。。。
map<pii, int> maparr[N][M];
string row[M];
map<string, int> idmap;
int strid;
int ID(string& str) {
if(idmap.count(str)) return idmap[str];
idmap[str] = strid;
return strid++;
}
void readrow() {
string tmp;
int ch;
while(ch = getchar(), !(ch >= ' ' && ch <= '~'));
tmp += ch;
for(int i = 1; i <= m; i++) {
for(;;) {
ch = getchar();
if(ch == ',') {row[i] = tmp; tmp.clear(); break;}
if(ch == '\n' || ch == '\r') {
row[i] = tmp; return;
}
tmp += ch;
}
}
}
bool check(int cur_row) {
for(int i = 1; i <= m; i++) {
for(int j = i + 1; j <= m; j++) {
pii t = {ID(row[i]), ID(row[j])};
// string t = ID(row[i]) + "," + ID(row[j]);
// cout << t << endl;
if(maparr[i][j].count(t)) {
puts("NO");
printf("%d %d\n", maparr[i][j][t], cur_row);
printf("%d %d\n", i, j);
return false;
}
maparr[i][j][t] = cur_row;
}
}
return true;
}
int main(void) {
while(cin >> n >> m) {
bool flag = true;
for(int i = 0; i < M; i++)
for(int j = 0; j < M; j++) maparr[i][j].clear();
for(int i = 1; i <= n; i++) {
readrow();
if(flag && !check(i)) flag = false;
}
if(flag) printf("YES\n");
}
return 0;
}