結果

問題 No.452 横着者のビンゴゲーム
ユーザー startcppstartcpp
提出日時 2017-01-01 23:12:17
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,571 bytes
コンパイル時間 1,341 ms
コンパイル使用メモリ 70,224 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-22 10:08:59
合計ジャッジ時間 24,864 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 10 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 13 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 6 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2,769 ms
4,380 KB
testcase_15 AC 2,706 ms
4,380 KB
testcase_16 AC 1,476 ms
4,376 KB
testcase_17 AC 103 ms
8,148 KB
testcase_18 AC 429 ms
4,384 KB
testcase_19 AC 246 ms
4,376 KB
testcase_20 AC 143 ms
5,716 KB
testcase_21 AC 1,074 ms
4,380 KB
testcase_22 AC 101 ms
7,744 KB
testcase_23 AC 1,990 ms
4,376 KB
testcase_24 AC 72 ms
7,832 KB
testcase_25 AC 44 ms
5,660 KB
testcase_26 AC 1,173 ms
4,376 KB
testcase_27 AC 743 ms
4,376 KB
testcase_28 AC 489 ms
4,376 KB
testcase_29 AC 268 ms
4,376 KB
testcase_30 AC 1,397 ms
4,376 KB
testcase_31 AC 193 ms
4,380 KB
testcase_32 AC 102 ms
4,376 KB
testcase_33 AC 535 ms
4,376 KB
testcase_34 AC 477 ms
4,376 KB
testcase_35 AC 307 ms
5,716 KB
testcase_36 AC 57 ms
5,632 KB
testcase_37 AC 53 ms
7,680 KB
testcase_38 TLE -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

//M = 2の場合:
//ビンゴカードを持っている人の目線で考える。ビンゴとは…縦横斜めのどれかのラインが消えること。
//2人のビンゴカードを比べる…1列ずつ取って(列A, Bとする)注目。2列のOR集合の数字を全て取ると, 2人は列A, 列Bでビンゴになる。
//つまりOR集合の大きさ - 1が解の上界になる。これを全ての列間について行い, OR集合の大きさの最小値 - 1を取ると, 解の上界=答えになる。
//M > 2の場合:
//人iと人jが同時にビンゴできる最小回数をf(i, j)とおく。「ある2人組がビンゴになる」のはダメなので解の上界=min(f(i, j)) - 1 (1 <= i < j <= M)になる。
//逆に, どの2人組もビンゴにならないなら, 3人以上がビンゴになることもないので, 解の下界=min(f(i, j)) - 1も成り立つ。
//したがって、min(f(i, j)) - 1が答えになる。
//計算量:(掛け算の厳密な順序は, ボトムアップに左から~(A * Bは, AをB回繰り返すであって, A回Bを繰り返すではない)だが, 実数において交換則が成り立つので、普段は逆転しててもよい)
//M^2組の人間各々について, O(N^2)組のラインを比較し, 各ライン比較はNlogN回かかるので…
//O(M^2 * N^3) = O((MN)^2 * NlogN)になる。MN <= 400, N <= 100だから、1億回くらいの計算が必要になる。C++なら間に合いそう。

#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

int n, m;
int c[200][100][100];

int f(int a, int b) {
	int i, j, k;
	static int as[202][100];
	static int bs[202][100];
	
	rep(i, n) rep(j, n) as[i][j] = c[a][i][j];
	rep(i, n) rep(j, n) as[n + i][j] = c[a][j][i];
	rep(i, n) as[2 * n][i] = c[a][i][i];
	rep(i, n) as[2 * n + 1][i] = c[a][i][n - 1 - i];
	
	rep(i, n) rep(j, n) bs[i][j] = c[b][i][j];
	rep(i, n) rep(j, n) bs[n + i][j] = c[b][j][i];
	rep(i, n) bs[2 * n][i] = c[b][i][i];
	rep(i, n) bs[2 * n + 1][i] = c[b][i][n - 1 - i];
	
	int ret = 114514;
	set<int> dict;
	rep(i, 2 * n + 2) {
		rep(j, 2 * n + 2) {
			dict.clear();
			rep(k, n) { dict.insert(as[i][k]); dict.insert(bs[j][k]); }
			ret = min(ret, (int)dict.size());
		}
	}
	return ret;
}

int main() {
	int i, j, k;
	
	cin >> n >> m;
	rep(i, m) rep(j, n) rep(k, n) cin >> c[i][j][k];
	
	int ans = 114514;
	for (i = 0; i < m; i++) for (j = i + 1; j < m; j++) ans = min(ans, f(i, j) - 1);
	cout << ans << endl;
	return 0;
}
0