結果

問題 No.452 横着者のビンゴゲーム
ユーザー olpheolphe
提出日時 2016-12-03 05:12:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,895 ms / 3,000 ms
コード長 2,399 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 63,584 KB
実行使用メモリ 7,856 KB
最終ジャッジ日時 2023-08-19 07:37:09
合計ジャッジ時間 15,174 ms
ジャッジサーバーID
(参考情報)
judge10 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 384 ms
4,380 KB
testcase_15 AC 379 ms
4,384 KB
testcase_16 AC 199 ms
4,384 KB
testcase_17 AC 33 ms
7,856 KB
testcase_18 AC 155 ms
4,380 KB
testcase_19 AC 84 ms
4,376 KB
testcase_20 AC 62 ms
5,676 KB
testcase_21 AC 409 ms
4,376 KB
testcase_22 AC 53 ms
7,772 KB
testcase_23 AC 774 ms
4,376 KB
testcase_24 AC 37 ms
7,696 KB
testcase_25 AC 23 ms
5,724 KB
testcase_26 AC 436 ms
4,376 KB
testcase_27 AC 232 ms
4,380 KB
testcase_28 AC 177 ms
4,376 KB
testcase_29 AC 87 ms
4,380 KB
testcase_30 AC 530 ms
4,380 KB
testcase_31 AC 60 ms
4,376 KB
testcase_32 AC 41 ms
4,380 KB
testcase_33 AC 172 ms
4,376 KB
testcase_34 AC 148 ms
4,376 KB
testcase_35 AC 110 ms
5,772 KB
testcase_36 AC 30 ms
5,692 KB
testcase_37 AC 28 ms
7,728 KB
testcase_38 AC 1,895 ms
4,384 KB
testcase_39 AC 1,219 ms
4,376 KB
testcase_40 AC 1,221 ms
4,380 KB
testcase_41 AC 1,219 ms
4,380 KB
testcase_42 AC 1,219 ms
4,380 KB
testcase_43 AC 1,218 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "algorithm"
using namespace std;

int N, M;
int card[200][100][100];
int ans=1000;
int box;
int check[2][100];

void same() {
	int x=0, y=0;
	box = N;
	while (x<N&&y<N) {
		if (check[0][x] == check[1][y]) {
			box--;
			x++;
			y++;
		}
		else if (check[0][x]>check[1][y]) {
			y++;
		}
		else {
			x++;
		}
	}
	if (ans > box)ans = box;
}
void _copy(int num,int y,int x,bool flag) {
	int a=0;
	if (!flag)a = 1;
	if (y == -1&&x!=-1) {
		for (int i = 0; i < N; i++) {
			check[a][i] = card[num][i][x];
		}
		sort(check[a], &check[a][N]);
	}
	else if (x == -1&&y!=-1) {
		for (int i = 0; i < N; i++) {
			check[a][i] = card[num][y][i];
		}
		sort(check[a], &check[a][N]);
	}
	else if(x==-1&&y==-1){
		for (int i = 0; i < N; i++) {
			check[a][i] = card[num][i][i];
		}
		sort(check[a], &check[a][N]);
	}
	else {
		for (int i = 0; i < N; i++) {
			check[a][i] = card[num][i][N-i-1];
		}
		sort(check[a], &check[a][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 >> card[i][j][k];
			}
		}
	}
	for (int h = 0; h < M; h++) {
		for (int i = 0; i < N; i++) {
			_copy(h, i, -1,true);
			for (int j = 0; j < M; j++) {
				if (h != j) {
					for (int k = 0; k < N; k++) {
						_copy(j, k, -1,false);
						same();
						_copy(j, -1, k, false);
						same();
					}
					_copy(j, -1, -1, false);
					same();
					_copy(j, 0, 0, false);
					same();
				}
			}
			_copy(h, -1, i, true);
			for (int j = 0; j < M; j++) {
				if (h != j) {
					for (int k = 0; k < N; k++) {
						_copy(j, k, -1, false);
						same();
						_copy(j, -1, k, false);
						same();
					}
					_copy(j, -1, -1, false);
					same();
					_copy(j, 0, 0, false);
					same();
				}
			}
		}
		_copy(h, -1, -1, true);
		for (int j = 0; j < M; j++) {
			if (h != j) {
				for (int k = 0; k < N; k++) {
					_copy(j, k, -1, false);
					same();
					_copy(j, -1, k, false);
					same();
				}
				_copy(j, -1, -1, false);
				same();
				_copy(j, 0, 0, false);
				same();
			}
		}
		_copy(h, 0, 0, true);
		for (int j = 0; j < M; j++) {
			if (h != j) {
				for (int k = 0; k < N; k++) {
					_copy(j, k, -1, false);
					same();
					_copy(j, -1, k, false);
					same();
				}
				_copy(j, -1, -1, false);
				same();
				_copy(j, 0, 0, false);
				same();
			}
		}
	}
	cout << ans + N-1 << "\n";
	return 0;
}
0