結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
37,248 KB
testcase_01 AC 55 ms
37,244 KB
testcase_02 AC 55 ms
37,228 KB
testcase_03 AC 62 ms
37,416 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 58 ms
36,860 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 55 ms
37,300 KB
testcase_10 WA -
testcase_11 AC 59 ms
37,356 KB
testcase_12 AC 56 ms
37,144 KB
testcase_13 AC 56 ms
37,528 KB
testcase_14 AC 278 ms
44,304 KB
testcase_15 AC 273 ms
44,388 KB
testcase_16 AC 183 ms
42,160 KB
testcase_17 AC 120 ms
40,796 KB
testcase_18 WA -
testcase_19 AC 152 ms
41,428 KB
testcase_20 AC 142 ms
41,824 KB
testcase_21 WA -
testcase_22 AC 136 ms
40,912 KB
testcase_23 AC 431 ms
43,504 KB
testcase_24 AC 124 ms
40,336 KB
testcase_25 AC 102 ms
38,688 KB
testcase_26 AC 270 ms
42,072 KB
testcase_27 AC 212 ms
43,912 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 338 ms
43,576 KB
testcase_31 AC 111 ms
39,152 KB
testcase_32 AC 123 ms
41,260 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 169 ms
41,636 KB
testcase_36 AC 95 ms
38,688 KB
testcase_37 AC 115 ms
40,200 KB
testcase_38 WA -
testcase_39 AC 605 ms
46,288 KB
testcase_40 AC 598 ms
46,284 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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[j][i];
                    }
                    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