結果

問題 No.452 横着者のビンゴゲーム
ユーザー 37zigen37zigen
提出日時 2016-12-04 00:38:41
言語 Java19
(openjdk 21)
結果
AC  
実行時間 662 ms / 3,000 ms
コード長 1,549 bytes
コンパイル時間 5,409 ms
コンパイル使用メモリ 80,600 KB
実行使用メモリ 69,816 KB
最終ジャッジ日時 2023-08-19 08:55:32
合計ジャッジ時間 17,958 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
53,532 KB
testcase_01 AC 99 ms
55,896 KB
testcase_02 AC 103 ms
55,520 KB
testcase_03 AC 133 ms
55,844 KB
testcase_04 AC 111 ms
55,760 KB
testcase_05 AC 130 ms
56,036 KB
testcase_06 AC 101 ms
55,732 KB
testcase_07 AC 107 ms
55,620 KB
testcase_08 AC 115 ms
55,684 KB
testcase_09 AC 101 ms
55,872 KB
testcase_10 AC 105 ms
55,864 KB
testcase_11 AC 110 ms
56,032 KB
testcase_12 AC 108 ms
55,656 KB
testcase_13 AC 96 ms
55,772 KB
testcase_14 AC 662 ms
69,816 KB
testcase_15 AC 658 ms
69,720 KB
testcase_16 AC 434 ms
60,748 KB
testcase_17 AC 224 ms
59,940 KB
testcase_18 AC 289 ms
60,820 KB
testcase_19 AC 269 ms
60,652 KB
testcase_20 AC 202 ms
60,040 KB
testcase_21 AC 322 ms
61,140 KB
testcase_22 AC 229 ms
60,112 KB
testcase_23 AC 416 ms
61,640 KB
testcase_24 AC 210 ms
59,900 KB
testcase_25 AC 192 ms
60,460 KB
testcase_26 AC 312 ms
61,608 KB
testcase_27 AC 284 ms
61,140 KB
testcase_28 AC 291 ms
60,920 KB
testcase_29 AC 259 ms
60,352 KB
testcase_30 AC 386 ms
61,540 KB
testcase_31 AC 238 ms
61,036 KB
testcase_32 AC 222 ms
59,948 KB
testcase_33 AC 301 ms
61,212 KB
testcase_34 AC 281 ms
61,048 KB
testcase_35 AC 274 ms
60,504 KB
testcase_36 AC 205 ms
60,132 KB
testcase_37 AC 171 ms
58,924 KB
testcase_38 AC 580 ms
63,012 KB
testcase_39 AC 469 ms
61,444 KB
testcase_40 AC 447 ms
61,584 KB
testcase_41 AC 496 ms
61,452 KB
testcase_42 AC 493 ms
61,424 KB
testcase_43 AC 446 ms
61,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Q452 {
	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[][][] table = new int[m][n][n];
		for (int i = 0; i < m; ++i) {
			for (int j = 0; j < n; ++j) {
				for (int k = 0; k < n; ++k) {
					table[i][j][k] = Integer.parseInt(sc.next());
				}
			}
		}
		ArrayList[][] list = new ArrayList[m][2 * n + 2];
		for (int i = 0; i < list.length; ++i) {
			for (int j = 0; j < list[i].length; ++j) {
				list[i][j] = new ArrayList<>();
			}
		}

		for (int i = 0; i < m; ++i) {
			int p = 0;
			for (int j = 0; j < n; ++j) {
				for (int k = 0; k < n; ++k) {
					list[i][p].add(table[i][j][k]);
					list[i][p + 1].add(table[i][k][j]);
				}
				p += 2;
				list[i][2 * n].add(table[i][j][j]);
				list[i][2 * n + 1].add(table[i][n - 1 - j][j]);
			}
		}

		int min = Integer.MAX_VALUE;
		for (int i = 0; i < m; ++i) {
			for (int j = i + 1; j < m; ++j) {
				for (ArrayList<Integer> list1 : list[i]) {
					boolean[] vis = new boolean[n * n * m + 1];
					for (int set1 : list1) {
						vis[set1] = true;
					}
					for (ArrayList<Integer> list2 : list[j]) {
						int count = 0;
						for (int set2 : list2) {
							if (vis[set2]) {
								++count;
							}
						}
						min = Math.min(2 * n - count - 1, min);
					}
				}
			}
		}
		System.out.println(min);
	}
}
0