結果

問題 No.452 横着者のビンゴゲーム
ユーザー startcppstartcpp
提出日時 2017-01-02 00:06:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 250 ms / 3,000 ms
コード長 1,314 bytes
コンパイル時間 518 ms
コンパイル使用メモリ 64,936 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2023-08-22 10:10:15
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 52 ms
4,380 KB
testcase_15 AC 50 ms
4,376 KB
testcase_16 AC 33 ms
4,380 KB
testcase_17 AC 9 ms
7,912 KB
testcase_18 AC 28 ms
4,376 KB
testcase_19 AC 21 ms
4,380 KB
testcase_20 AC 16 ms
5,720 KB
testcase_21 AC 61 ms
4,376 KB
testcase_22 AC 15 ms
7,668 KB
testcase_23 AC 109 ms
4,380 KB
testcase_24 AC 10 ms
7,732 KB
testcase_25 AC 7 ms
5,620 KB
testcase_26 AC 70 ms
4,376 KB
testcase_27 AC 52 ms
4,380 KB
testcase_28 AC 31 ms
4,376 KB
testcase_29 AC 22 ms
4,376 KB
testcase_30 AC 80 ms
4,380 KB
testcase_31 AC 15 ms
4,380 KB
testcase_32 AC 11 ms
4,376 KB
testcase_33 AC 38 ms
4,384 KB
testcase_34 AC 33 ms
4,376 KB
testcase_35 AC 28 ms
5,708 KB
testcase_36 AC 8 ms
5,796 KB
testcase_37 AC 8 ms
7,824 KB
testcase_38 AC 250 ms
4,376 KB
testcase_39 AC 174 ms
4,376 KB
testcase_40 AC 174 ms
4,380 KB
testcase_41 AC 174 ms
4,376 KB
testcase_42 AC 175 ms
4,380 KB
testcase_43 AC 174 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#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, l;
	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];
	
	rep(i, 2 * n + 2) sort(as[i], as[i] + n);
	rep(i, 2 * n + 2) sort(bs[i], bs[i] + n);
	
	int ret = 114514;
	rep(i, 2 * n + 2) {
		rep(j, 2 * n + 2) {
			//|as[i] or bs[j]|を求める。(尺取り法でO(N))
			int sz = 0;
			
			l = 0;
			for (k = 0; k < n; k++) {
				for (; l < n; l++) {
					if (as[i][k] <= bs[j][l]) {
						break;
					}
				}
				if (l == n) { break; }
				sz += (as[i][k] == bs[j][l]);
			}
			sz = 2 * n - sz;
			
			ret = min(ret, sz);
		}
	}
	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