結果

問題 No.452 横着者のビンゴゲーム
ユーザー 37zigen37zigen
提出日時 2016-12-03 23:52:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,656 ms / 3,000 ms
コード長 1,442 bytes
コンパイル時間 4,949 ms
コンパイル使用メモリ 80,588 KB
実行使用メモリ 65,636 KB
最終ジャッジ日時 2023-08-18 13:52:49
合計ジャッジ時間 45,826 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
55,920 KB
testcase_01 AC 129 ms
55,352 KB
testcase_02 AC 136 ms
55,752 KB
testcase_03 AC 231 ms
58,364 KB
testcase_04 AC 165 ms
55,768 KB
testcase_05 AC 242 ms
58,988 KB
testcase_06 AC 132 ms
55,548 KB
testcase_07 AC 178 ms
57,740 KB
testcase_08 AC 205 ms
58,504 KB
testcase_09 AC 133 ms
55,916 KB
testcase_10 AC 164 ms
55,900 KB
testcase_11 AC 192 ms
58,252 KB
testcase_12 AC 174 ms
55,864 KB
testcase_13 AC 127 ms
56,108 KB
testcase_14 AC 2,455 ms
65,636 KB
testcase_15 AC 2,297 ms
62,984 KB
testcase_16 AC 1,549 ms
63,332 KB
testcase_17 AC 477 ms
60,660 KB
testcase_18 AC 627 ms
60,224 KB
testcase_19 AC 604 ms
61,080 KB
testcase_20 AC 489 ms
60,288 KB
testcase_21 AC 989 ms
60,768 KB
testcase_22 AC 486 ms
61,812 KB
testcase_23 AC 1,532 ms
62,820 KB
testcase_24 AC 463 ms
61,128 KB
testcase_25 AC 414 ms
60,064 KB
testcase_26 AC 1,146 ms
60,596 KB
testcase_27 AC 818 ms
60,616 KB
testcase_28 AC 804 ms
58,472 KB
testcase_29 AC 574 ms
60,608 KB
testcase_30 AC 1,106 ms
62,916 KB
testcase_31 AC 480 ms
60,408 KB
testcase_32 AC 435 ms
59,596 KB
testcase_33 AC 761 ms
60,936 KB
testcase_34 AC 725 ms
60,788 KB
testcase_35 AC 602 ms
60,816 KB
testcase_36 AC 442 ms
59,992 KB
testcase_37 AC 498 ms
60,696 KB
testcase_38 AC 2,656 ms
65,428 KB
testcase_39 AC 2,477 ms
62,960 KB
testcase_40 AC 2,369 ms
62,548 KB
testcase_41 AC 2,453 ms
62,944 KB
testcase_42 AC 2,400 ms
62,940 KB
testcase_43 AC 2,381 ms
63,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

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

public class Q452 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		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] = sc.nextInt();
				}
			}
		}
		ArrayList<Set<Integer>>[] list = new ArrayList[m];
		for (int i = 0; i < m; ++i)
			list[i] = new ArrayList<>();

		for (int i = 0; i < m; ++i) {
			Set<Integer> set3 = new HashSet<>();
			Set<Integer> set4 = new HashSet<>();
			for (int j = 0; j < n; ++j) {
				Set<Integer> set1 = new HashSet<>();
				Set<Integer> set2 = new HashSet<>();
				for (int k = 0; k < n; ++k) {
					set1.add(table[i][j][k]);
					set2.add(table[i][k][j]);
				}
				set3.add(table[i][j][j]);
				set4.add(table[i][n - 1 - j][j]);
				list[i].add(set1);
				list[i].add(set2);
			}
			list[i].add(set3);
			list[i].add(set4);
		}

		int min = Integer.MAX_VALUE;

		for (int i = 0; i < m; ++i) {
			for (int j = i + 1; j < m; ++j) {
				for (Set<Integer> set1 : list[i]) {
					for (Set<Integer> set2 : list[j]) {
						Set<Integer> sum = new HashSet<>();
						sum.addAll(set1);
						sum.addAll(set2);
						min = Math.min(sum.size(), min);
					}
				}
			}
		}
		System.out.println(min - 1);
	}
}
0