結果

問題 No.452 横着者のビンゴゲーム
ユーザー fal_rndfal_rnd
提出日時 2016-12-04 01:26:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 705 ms / 3,000 ms
コード長 1,460 bytes
コンパイル時間 5,141 ms
コンパイル使用メモリ 79,952 KB
実行使用メモリ 65,840 KB
最終ジャッジ日時 2023-08-19 09:02:39
合計ジャッジ時間 19,330 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
55,968 KB
testcase_01 AC 124 ms
55,716 KB
testcase_02 AC 128 ms
56,096 KB
testcase_03 AC 171 ms
58,440 KB
testcase_04 AC 135 ms
55,764 KB
testcase_05 AC 189 ms
57,496 KB
testcase_06 AC 125 ms
55,936 KB
testcase_07 AC 134 ms
55,964 KB
testcase_08 AC 147 ms
55,768 KB
testcase_09 AC 127 ms
55,756 KB
testcase_10 AC 134 ms
55,996 KB
testcase_11 AC 137 ms
56,120 KB
testcase_12 AC 132 ms
56,220 KB
testcase_13 AC 125 ms
55,616 KB
testcase_14 AC 705 ms
65,744 KB
testcase_15 AC 700 ms
65,840 KB
testcase_16 AC 536 ms
63,040 KB
testcase_17 AC 258 ms
59,776 KB
testcase_18 AC 347 ms
58,652 KB
testcase_19 AC 339 ms
60,824 KB
testcase_20 AC 281 ms
59,784 KB
testcase_21 AC 408 ms
61,020 KB
testcase_22 AC 261 ms
59,580 KB
testcase_23 AC 521 ms
63,496 KB
testcase_24 AC 270 ms
59,784 KB
testcase_25 AC 242 ms
59,548 KB
testcase_26 AC 418 ms
61,028 KB
testcase_27 AC 421 ms
60,544 KB
testcase_28 AC 352 ms
60,216 KB
testcase_29 AC 338 ms
61,084 KB
testcase_30 AC 430 ms
60,724 KB
testcase_31 AC 311 ms
60,196 KB
testcase_32 AC 238 ms
60,940 KB
testcase_33 AC 380 ms
60,436 KB
testcase_34 AC 351 ms
60,476 KB
testcase_35 AC 378 ms
60,396 KB
testcase_36 AC 248 ms
59,380 KB
testcase_37 AC 262 ms
59,420 KB
testcase_38 AC 698 ms
63,812 KB
testcase_39 AC 593 ms
63,408 KB
testcase_40 AC 594 ms
63,388 KB
testcase_41 AC 590 ms
63,004 KB
testcase_42 AC 586 ms
61,676 KB
testcase_43 AC 585 ms
63,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package src;

import java.util.*;
class B{
	static Scanner s = new Scanner(System.in);
	public static void main(String[] args) {
		int size = s.nextInt();
		int[][] in = new int[size][size];
		Card[] cards = new Card[s.nextInt()];
		for (int i=0;i<cards.length;i++) {

			for(int j=0;j<size;j++)
				for(int k=0;k<size;k++)
					in[j][k] = Integer.parseInt(s.next());

			cards[i] = new Card(in,size*size*cards.length);
		}
		int v=0;
		for(int i=0;i<cards.length;i++) {
			for(int j=i+1;j<cards.length;j++) {
				v=Math.max(v, cards[i].match(cards[j]));
			}
		}
		System.out.println(size*2-1-v);
	}
}
class Card{
	ArrayList<BitSet> edge;
	Card(int[][] in,int max) {
		int size = in.length;
		edge = new ArrayList<>(in.length*2+2);
		BitSet
			h =new BitSet(max),
			v =new BitSet(max),
			t1=new BitSet(max),
			t2=new BitSet(max);

		for(int i=0;i<size;++i) {
			h.clear();
			v.clear();
			for(int j=0;j<size;++j) {
				h.set(in[i][j]);
				v.set(in[j][i]);
			}
			edge.add((BitSet)h.clone());
			edge.add((BitSet)v.clone());
			t1.set(in[i][i]);
			t2.set(in[i][size-i-1]);
		}
		edge.add(t1);
		edge.add(t2);
	}

	public int match(Card card) {
		int r=0,max=edge.get(0).cardinality();
		roop:
		for(int i=0;i<edge.size();i++) {
			BitSet b = card.edge.get(i);
			for(int j=0;j<edge.size();j++) {
				BitSet bb = ((BitSet) b.clone());
				bb.and(edge.get(j));
				r=Math.max(r, bb.cardinality());
				if(r==max)
					break roop;
			}
		}
		return r;
	}
}
0