Adding some more judges, here and there.
[andmenj-acm.git] / NEERC / database / database_gk.java
blob78c449c02673b658af75fcdc076b933aae5af3ea
1 import java.util.*;
2 import java.io.*;
4 public class database_gk {
5 static BufferedReader in;
6 static PrintWriter out;
8 public void run() throws IOException {
9 String l = in.readLine();
10 int n = Integer.parseInt(l.split(" ")[0]);
11 int m = Integer.parseInt(l.split(" ")[1]);
13 String[][] values = new String[n][];
14 for (int i = 0; i < n; i++) {
15 String line = in.readLine();
16 String[] result = new String[m];
17 int index = 0;
18 for (int j = 0; j < m - 1; j++) {
19 int nindex = line.indexOf(',', index);
20 result[j] = line.substring(index, nindex);
21 index = nindex + 1;
23 result[m - 1] = line.substring(index);
24 values[i] = result;
27 Map<String, Integer> intern = new HashMap<String, Integer>();
28 int[][] indices = new int[n][m];
29 int maxIndex = 0;
30 for (int i = 0; i < n; i++) {
31 for (int j = 0; j < m; j++) {
32 String value = values[i][j];
33 Integer index = intern.get(value);
34 if (index == null) {
35 index = maxIndex++;
36 intern.put(value, index);
38 indices[i][j] = index;
42 for (int c1 = 0; c1 < m; c1++) {
43 for (int c2 = c1 + 1; c2 < m; c2++) {
44 long[] pairs = new long[n];
45 for (int r = 0; r < n; r++) {
46 pairs[r] = ((long) indices[r][c1] * maxIndex + indices[r][c2]) * n + r;
48 Arrays.sort(pairs);
49 for (int i = 0; i < n - 1; i++) {
50 if (pairs[i] / n == pairs[i + 1] / n) {
51 out.println("NO");
52 out.println((pairs[i] % n + 1) + " " + (pairs[i + 1] % n + 1));
53 out.println((c1 + 1) + " " + (c2 + 1));
54 return;
59 out.println("YES");
62 public static void main(String[] args) throws Exception {
63 in = new BufferedReader(new FileReader("database.in"));
64 out = new PrintWriter("database.out");
66 new database_gk().run();
68 in.close();
69 out.close();