結果

問題 No.452 横着者のビンゴゲーム
ユーザー zimphazimpha
提出日時 2017-04-02 13:04:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 754 ms / 3,000 ms
コード長 4,348 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 78,232 KB
実行使用メモリ 47,328 KB
最終ジャッジ日時 2024-07-08 00:02:57
合計ジャッジ時間 12,202 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
37,624 KB
testcase_01 AC 54 ms
37,324 KB
testcase_02 AC 55 ms
37,344 KB
testcase_03 AC 64 ms
37,524 KB
testcase_04 AC 55 ms
37,300 KB
testcase_05 AC 64 ms
38,432 KB
testcase_06 AC 55 ms
37,300 KB
testcase_07 AC 55 ms
37,268 KB
testcase_08 AC 57 ms
37,360 KB
testcase_09 AC 53 ms
37,464 KB
testcase_10 AC 53 ms
37,624 KB
testcase_11 AC 57 ms
37,144 KB
testcase_12 AC 53 ms
37,408 KB
testcase_13 AC 54 ms
37,144 KB
testcase_14 AC 282 ms
44,216 KB
testcase_15 AC 255 ms
43,724 KB
testcase_16 AC 180 ms
42,288 KB
testcase_17 AC 119 ms
40,832 KB
testcase_18 AC 165 ms
39,976 KB
testcase_19 AC 154 ms
41,604 KB
testcase_20 AC 136 ms
41,384 KB
testcase_21 AC 276 ms
42,108 KB
testcase_22 AC 131 ms
41,248 KB
testcase_23 AC 421 ms
45,108 KB
testcase_24 AC 122 ms
41,424 KB
testcase_25 AC 90 ms
38,548 KB
testcase_26 AC 266 ms
42,248 KB
testcase_27 AC 222 ms
44,704 KB
testcase_28 AC 181 ms
41,172 KB
testcase_29 AC 148 ms
41,664 KB
testcase_30 AC 300 ms
43,784 KB
testcase_31 AC 107 ms
38,880 KB
testcase_32 AC 122 ms
40,896 KB
testcase_33 AC 199 ms
43,072 KB
testcase_34 AC 185 ms
42,948 KB
testcase_35 AC 166 ms
41,564 KB
testcase_36 AC 94 ms
38,656 KB
testcase_37 AC 107 ms
40,840 KB
testcase_38 AC 754 ms
47,328 KB
testcase_39 AC 593 ms
46,576 KB
testcase_40 AC 602 ms
46,348 KB
testcase_41 AC 590 ms
45,780 KB
testcase_42 AC 584 ms
46,504 KB
testcase_43 AC 575 ms
45,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Chiaki.Hoshinomori
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task452 solver = new Task452();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task452 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[][] line = new int[n * m * 2 + 2 * m][];
            int sz = 0;
            int ret = n * 2;
            for (int it = 0; it < m; it++) {
                int[][] card = new int[n][];
                int new_sz = sz;
                for (int j = 0; j < n; j++) {
                    card[j] = in.nextIntArray(n);
                }
                for (int i = 0; i < n; i++) {
                    int[] a = new int[n];
                    for (int j = 0; j < n; j++) {
                        a[j] = card[i][j];
                    }
                    Arrays.sort(a);
                    for (int k = 0; k < sz; k++) {
                        ret = Math.min(ret, intersect(a, line[k]));
                    }
                    line[new_sz++] = a;
                }
                for (int j = 0; j < n; j++) {
                    int[] a = new int[n];
                    for (int i = 0; i < n; i++) {
                        a[i] = card[i][j];
                    }
                    Arrays.sort(a);
                    for (int k = 0; k < sz; k++) {
                        ret = Math.min(ret, intersect(a, line[k]));
                    }
                    line[new_sz++] = a;
                }
                int[] a = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = card[i][i];
                }
                Arrays.sort(a);
                for (int k = 0; k < sz; k++) {
                    ret = Math.min(ret, intersect(a, line[k]));
                }
                line[new_sz++] = a;
                a = new int[n];
                for (int i = 0; i < n; i++) {
                    a[i] = card[i][n - 1 - i];
                }
                Arrays.sort(a);
                for (int k = 0; k < sz; k++) {
                    ret = Math.min(ret, intersect(a, line[k]));
                }
                line[new_sz++] = a;
                sz = new_sz;
            }
            out.println(ret - 1);
        }

        private int intersect(int[] a, int[] b) {
            int cnt = a.length + b.length;
            for (int i = 0, j = 0; i < a.length && j < b.length; ) {
                if (a[i] == b[j]) {
                    --cnt;
                    ++i;
                    ++j;
                } else if (a[i] < b[j]) {
                    ++i;
                } else {
                    ++j;
                }
            }
            return cnt;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] nextIntArray(int n) {
            int[] r = new int[n];
            for (int i = 0; i < n; i++) {
                r[i] = nextInt();
            }
            return r;
        }

    }
}

0