結果

問題 No.452 横着者のビンゴゲーム
ユーザー mayoko_mayoko_
提出日時 2016-12-03 01:26:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 443 ms / 3,000 ms
コード長 2,453 bytes
コンパイル時間 1,085 ms
コンパイル使用メモリ 89,648 KB
実行使用メモリ 11,900 KB
最終ジャッジ日時 2023-08-19 06:59:33
合計ジャッジ時間 5,733 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 132 ms
4,380 KB
testcase_15 AC 120 ms
4,388 KB
testcase_16 AC 69 ms
4,384 KB
testcase_17 AC 23 ms
11,900 KB
testcase_18 AC 38 ms
4,380 KB
testcase_19 AC 25 ms
5,816 KB
testcase_20 AC 22 ms
5,564 KB
testcase_21 AC 94 ms
4,380 KB
testcase_22 AC 18 ms
7,752 KB
testcase_23 AC 177 ms
4,376 KB
testcase_24 AC 18 ms
9,984 KB
testcase_25 AC 8 ms
5,600 KB
testcase_26 AC 102 ms
4,376 KB
testcase_27 AC 65 ms
4,380 KB
testcase_28 AC 43 ms
4,380 KB
testcase_29 AC 26 ms
4,376 KB
testcase_30 AC 124 ms
4,380 KB
testcase_31 AC 17 ms
4,384 KB
testcase_32 AC 13 ms
5,692 KB
testcase_33 AC 49 ms
4,380 KB
testcase_34 AC 45 ms
4,376 KB
testcase_35 AC 32 ms
5,960 KB
testcase_36 AC 11 ms
5,820 KB
testcase_37 AC 13 ms
9,988 KB
testcase_38 AC 443 ms
4,380 KB
testcase_39 AC 281 ms
4,376 KB
testcase_40 AC 276 ms
4,376 KB
testcase_41 AC 288 ms
4,380 KB
testcase_42 AC 312 ms
4,376 KB
testcase_43 AC 313 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<queue>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int MAXM = 222;
const int MAXN = 111;

int C[MAXM][MAXN][MAXN];
bool done[MAXN][MAXN];
int N, M;

int cnt() {
	int ret = N;
	for (int i = 0; i < N; i++) {
		int tmp = 0;
		for (int j = 0; j < N; j++) {
			if (done[i][j]) ++tmp;
		}
		ret = min(ret, N-tmp);
	}
	for (int j = 0; j < N; j++) {
		int tmp = 0;
		for (int i = 0; i < N; i++) {
			if (done[i][j]) ++tmp;
		}
		ret = min(ret, N-tmp);
	}
	int tmp = 0;
	for (int i = 0; i < N; i++) {
		if (done[i][i]) ++tmp;
	}
	ret = min(ret, N-tmp);
	tmp = 0;
	for (int i = 0; i < N; i++) {
		if (done[i][N-1-i]) ++tmp;
	}
	ret = min(ret, N-tmp);
	return ret;
}

int calc(int a, int b) {
	int ans = N-1;
	for (int i = 0; i < N; i++) {
		set<int> S;
		for (int j = 0; j < N; j++) {
			S.insert(C[a][i][j]);
		}
		memset(done, false, sizeof(done));
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (S.find(C[b][i][j]) != S.end()) done[i][j] = true;
			}
		}
		ans = min(ans, cnt()-1);
	}
	for (int j = 0; j < N; j++) {
		set<int> S;
		for (int i = 0; i < N; i++) {
			S.insert(C[a][i][j]);
		}
		memset(done, false, sizeof(done));
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (S.find(C[b][i][j]) != S.end()) done[i][j] = true;
			}
		}
		ans = min(ans, cnt()-1);
	}
	{
		set<int> S;
		for (int i = 0; i < N; i++) {
			S.insert(C[a][i][i]);
		}
		memset(done, false, sizeof(done));
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (S.find(C[b][i][j]) != S.end()) done[i][j] = true;
			}
		}
		ans = min(ans, cnt()-1);
	}
	{
		set<int> S;
		for (int i = 0; i < N; i++) {
			S.insert(C[a][i][N-1-i]);
		}
		memset(done, false, sizeof(done));
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (S.find(C[b][i][j]) != S.end()) done[i][j] = true;
			}
		}
		ans = min(ans, cnt()-1);
	}
	return ans+N;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				cin >> C[i][j][k];
			}
		}
	}
	int ans = 2*N-1;
	for (int i = 0; i < M; i++) {
		for (int j = i+1; j < M; j++) {
			ans = min(ans, calc(i, j));
		}
	}
	cout << ans << endl;
	return 0;
}
0