結果

問題 No.452 横着者のビンゴゲーム
ユーザー olpheolphe
提出日時 2016-12-03 05:01:41
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,334 bytes
コンパイル時間 540 ms
コンパイル使用メモリ 61,764 KB
実行使用メモリ 9,788 KB
最終ジャッジ日時 2024-05-05 17:56:41
合計ジャッジ時間 15,532 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1 ms
5,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 547 ms
5,376 KB
testcase_15 AC 527 ms
5,376 KB
testcase_16 AC 297 ms
5,376 KB
testcase_17 AC 38 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 440 ms
5,376 KB
testcase_22 WA -
testcase_23 AC 844 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 471 ms
5,376 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2,075 ms
5,376 KB
testcase_39 AC 1,299 ms
5,376 KB
testcase_40 AC 1,323 ms
5,376 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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