結果

問題 No.452 横着者のビンゴゲーム
ユーザー zimphazimpha
提出日時 2017-04-02 13:04:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 804 ms / 3,000 ms
コード長 4,348 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 74,752 KB
実行使用メモリ 61,320 KB
最終ジャッジ日時 2023-09-22 07:31:04
合計ジャッジ時間 12,749 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,616 KB
testcase_01 AC 43 ms
49,868 KB
testcase_02 AC 43 ms
49,812 KB
testcase_03 AC 54 ms
50,940 KB
testcase_04 AC 44 ms
49,620 KB
testcase_05 AC 54 ms
50,696 KB
testcase_06 AC 42 ms
49,576 KB
testcase_07 AC 43 ms
49,536 KB
testcase_08 AC 47 ms
49,676 KB
testcase_09 AC 43 ms
49,660 KB
testcase_10 AC 45 ms
49,540 KB
testcase_11 AC 47 ms
49,824 KB
testcase_12 AC 45 ms
49,804 KB
testcase_13 AC 43 ms
49,540 KB
testcase_14 AC 238 ms
56,872 KB
testcase_15 AC 231 ms
56,720 KB
testcase_16 AC 163 ms
54,240 KB
testcase_17 AC 114 ms
54,408 KB
testcase_18 AC 163 ms
54,388 KB
testcase_19 AC 137 ms
54,944 KB
testcase_20 AC 121 ms
55,120 KB
testcase_21 AC 262 ms
55,884 KB
testcase_22 AC 124 ms
55,188 KB
testcase_23 AC 394 ms
56,124 KB
testcase_24 AC 111 ms
54,368 KB
testcase_25 AC 90 ms
52,128 KB
testcase_26 AC 274 ms
55,924 KB
testcase_27 AC 217 ms
56,928 KB
testcase_28 AC 168 ms
54,984 KB
testcase_29 AC 145 ms
55,212 KB
testcase_30 AC 303 ms
56,636 KB
testcase_31 AC 97 ms
52,212 KB
testcase_32 AC 93 ms
52,396 KB
testcase_33 AC 183 ms
56,472 KB
testcase_34 AC 173 ms
56,068 KB
testcase_35 AC 146 ms
55,820 KB
testcase_36 AC 101 ms
54,340 KB
testcase_37 AC 105 ms
54,892 KB
testcase_38 AC 804 ms
61,320 KB
testcase_39 AC 569 ms
60,004 KB
testcase_40 AC 564 ms
58,580 KB
testcase_41 AC 553 ms
59,360 KB
testcase_42 AC 565 ms
58,572 KB
testcase_43 AC 537 ms
59,292 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