Adding some more judges, here and there.
[and.git] / NEERC / database / database_gk_ok_cpp_full_compact.cpp
blob2b3e6c22363445c2a4aa983213b5afaad634f202
1 #include <iostream>
2 #include <fstream>
3 #include <string>
4 #include <vector>
5 #include <algorithm>
6 #include <map>
8 using namespace std;
10 int main() {
11 ifstream in; in.open("database.in");
12 ofstream out; out.open("database.out");
14 int n;
15 int m;
16 in >> n >> m;
17 in.ignore();
19 cout << n << endl;
20 pair<string, int>* pairs = new pair<string, int>[n * m];
21 for (int i = 0; i < n; i++) {
22 char buffer[100];
24 for (int j = 0; j < m - 1; j++) {
25 in.getline(buffer, sizeof(buffer) / sizeof(char), ',');
26 pairs[j * n + i] = pair<string, int>(buffer, j * n + i);
29 in.getline(buffer, sizeof(buffer) / sizeof(char), '\n');
30 pairs[(m - 1) * n + i] = pair<string, int>(buffer, (m - 1) * n + i);
33 sort(pairs, pairs + n * m);
35 int* a = new int[n * m];
36 int index = 0;
37 string prev = "";
38 for (int i = 0; i < n * m; i++) {
39 if (prev != pairs[i].first) {
40 prev = pairs[i].first;
41 index++;
43 a[pairs[i].second] = index;
46 for (int c1 = 0; c1 < m; c1++) {
47 for (int c2 = c1 + 1; c2 < m; c2++) {
48 int* col1 = a + c1 * n;
49 int* col2 = a + c2 * n;
50 for (int r1 = 0; r1 < n; r1++) {
51 int val1 = col1[r1];
52 int val2 = col2[r1];
53 for (int r2 = r1 + 1; r2 < n; r2++) {
54 if (val1 == col1[r2] && val2 == col2[r2]) {
55 out << "NO" << endl;
56 out << (r2 + 1) << " " << (r1 + 1) << endl;
57 out << (c1 + 1) << " " << (c2 + 1) << endl;
58 return 0;
65 out << "YES" << endl;
67 in.close();
68 out.close();
70 return 0;