結果

問題 No.452 横着者のビンゴゲーム
ユーザー startcppstartcpp
提出日時 2017-01-02 00:06:27
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 259 ms / 3,000 ms
コード長 1,314 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 61,392 KB
実行使用メモリ 9,556 KB
最終ジャッジ日時 2024-05-09 15:48:32
合計ジャッジ時間 3,631 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 46 ms
6,944 KB
testcase_15 AC 46 ms
6,940 KB
testcase_16 AC 29 ms
6,944 KB
testcase_17 AC 10 ms
7,832 KB
testcase_18 AC 30 ms
6,944 KB
testcase_19 AC 23 ms
6,940 KB
testcase_20 AC 18 ms
6,940 KB
testcase_21 AC 67 ms
6,940 KB
testcase_22 AC 15 ms
7,728 KB
testcase_23 AC 108 ms
6,944 KB
testcase_24 AC 10 ms
9,556 KB
testcase_25 AC 7 ms
6,940 KB
testcase_26 AC 72 ms
6,940 KB
testcase_27 AC 56 ms
6,940 KB
testcase_28 AC 33 ms
6,944 KB
testcase_29 AC 22 ms
6,940 KB
testcase_30 AC 83 ms
6,940 KB
testcase_31 AC 16 ms
6,944 KB
testcase_32 AC 13 ms
6,940 KB
testcase_33 AC 40 ms
6,940 KB
testcase_34 AC 35 ms
6,944 KB
testcase_35 AC 30 ms
6,940 KB
testcase_36 AC 8 ms
6,940 KB
testcase_37 AC 8 ms
7,668 KB
testcase_38 AC 259 ms
6,940 KB
testcase_39 AC 172 ms
6,940 KB
testcase_40 AC 180 ms
6,940 KB
testcase_41 AC 182 ms
6,940 KB
testcase_42 AC 183 ms
6,944 KB
testcase_43 AC 179 ms
6,940 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