結果

問題 No.452 横着者のビンゴゲーム
ユーザー startcppstartcpp
提出日時 2017-01-01 23:17:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2,778 ms / 3,000 ms
コード長 2,595 bytes
コンパイル時間 756 ms
コンパイル使用メモリ 75,380 KB
実行使用メモリ 7,892 KB
最終ジャッジ日時 2023-08-22 10:09:34
合計ジャッジ時間 28,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 10 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 5 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2,778 ms
4,380 KB
testcase_15 AC 2,684 ms
4,380 KB
testcase_16 AC 1,653 ms
4,380 KB
testcase_17 AC 137 ms
7,892 KB
testcase_18 AC 274 ms
4,380 KB
testcase_19 AC 189 ms
4,376 KB
testcase_20 AC 148 ms
5,632 KB
testcase_21 AC 618 ms
4,380 KB
testcase_22 AC 121 ms
7,660 KB
testcase_23 AC 1,149 ms
4,376 KB
testcase_24 AC 92 ms
7,724 KB
testcase_25 AC 52 ms
5,604 KB
testcase_26 AC 684 ms
4,376 KB
testcase_27 AC 527 ms
4,376 KB
testcase_28 AC 310 ms
4,376 KB
testcase_29 AC 194 ms
4,380 KB
testcase_30 AC 802 ms
4,380 KB
testcase_31 AC 138 ms
4,376 KB
testcase_32 AC 95 ms
4,376 KB
testcase_33 AC 383 ms
4,380 KB
testcase_34 AC 311 ms
4,376 KB
testcase_35 AC 267 ms
5,680 KB
testcase_36 AC 68 ms
5,604 KB
testcase_37 AC 68 ms
7,748 KB
testcase_38 AC 2,569 ms
4,376 KB
testcase_39 AC 1,832 ms
4,376 KB
testcase_40 AC 1,830 ms
4,380 KB
testcase_41 AC 1,828 ms
4,376 KB
testcase_42 AC 1,828 ms
4,380 KB
testcase_43 AC 1,826 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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)組のラインを比較し, 各ライン比較はN回かかるので…
//O(M^2 * N^3) = O((MN)^2 * NlogN)になる。MN <= 400, N <= 100だから、1600万回くらいの計算が必要になる(実際は * 4くらい)。C++なら間に合いそう。

#include <iostream>
#include <algorithm>
#include <unordered_set>
#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;
	unordered_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