結果

問題 No.452 横着者のビンゴゲーム
ユーザー mayoko_
提出日時 2016-12-03 01:26:43
言語 C++14
(gcc 8.3.0)
結果
AC  
実行時間 456 ms
コード長 2,453 Byte
コンパイル時間 861 ms
使用メモリ 2,376 KB
最終ジャッジ日時 2019-12-04 04:23:30

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0_sample_1 AC 4 ms
1,516 KB
0_sample_2 AC 4 ms
1,516 KB
0_sample_3 AC 4 ms
1,520 KB
1_small_0 AC 4 ms
1,552 KB
1_small_1 AC 3 ms
1,520 KB
1_small_2 AC 5 ms
1,568 KB
1_small_3 AC 4 ms
1,532 KB
1_small_4 AC 3 ms
1,532 KB
1_small_5 AC 5 ms
1,544 KB
1_small_6 AC 4 ms
1,532 KB
1_small_7 AC 4 ms
1,524 KB
1_small_8 AC 5 ms
1,528 KB
1_small_9 AC 4 ms
1,524 KB
challenge01.txt AC 3 ms
1,512 KB
hand_0 AC 116 ms
1,700 KB
hand_1 AC 112 ms
1,688 KB
hand_2 AC 74 ms
1,700 KB
hand_3 AC 55 ms
2,376 KB
random_00 AC 45 ms
1,616 KB
random_01 AC 33 ms
1,792 KB
random_02 AC 34 ms
1,952 KB
random_03 AC 105 ms
1,632 KB
random_04 AC 34 ms
2,044 KB
random_05 AC 191 ms
1,652 KB
random_06 AC 40 ms
2,216 KB
random_07 AC 18 ms
1,856 KB
random_08 AC 113 ms
1,668 KB
random_09 AC 77 ms
1,792 KB
random_10 AC 50 ms
1,632 KB
random_11 AC 32 ms
1,736 KB
random_12 AC 133 ms
1,652 KB
random_13 AC 24 ms
1,644 KB
random_14 AC 19 ms
1,776 KB
random_15 AC 58 ms
1,772 KB
random_16 AC 52 ms
1,696 KB
random_17 AC 44 ms
1,892 KB
random_18 AC 21 ms
1,912 KB
random_19 AC 30 ms
2,108 KB
random_20 AC 456 ms
1,688 KB
random_21 AC 297 ms
1,696 KB
random_22 AC 297 ms
1,700 KB
random_23 AC 292 ms
1,700 KB
random_24 AC 293 ms
1,704 KB
random_25 AC 301 ms
1,700 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