记录编号 191943 评测结果 AAAAAAAAAA
题目名称 Blue Mary的战役地图 最终得分 100
用户昵称 Gravatar啊吧啦吧啦吧 是否通过 通过
代码语言 C++ 运行时间 1.066 s
提交时间 2015-10-09 12:00:07 内存使用 0.33 MiB
显示代码纯文本
//T:O(n^6logn) luangao
//#define self
//#define debug
#include <iostream>
#include <cstdio>

const int MAXN(51);
inline int qread();
int n, map1[MAXN][MAXN], map2[MAXN][MAXN];
bool ok[MAXN] = {false};
FILE *fin, *fout;
inline bool okay(int);

main(){
#ifdef debug
	printf("%lf\n", sizeof(map1) / 1024.0 / 1024.0);
#endif
#ifdef self
	fin = stdin;
	fout = stdout;
#else
	fin = fopen("campaign.in", "rb");
	fout = fopen("campaign.out", "wb");
#endif
	n = qread();
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			map1[i][j] = qread();
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= n; ++j)
			map2[i][j] = qread();
	fclose(fin);
	
	int l = 0, r = n + 1, mid;
	while (l < r - 1){
		mid = (r + l) >> 1;
		if (okay(mid))
			l = mid;
		else
			r = mid;
	}
	
	fprintf(fout, "%d", l);
	fclose(fout);
#ifdef debug
	for (; ; );
#endif
}

inline int qread(){
	int x = 0;
	char c;
	while (! isdigit(c = fgetc(fin)));
	while (isdigit(c)){
		x = x * 10 + c - '0';
		c = fgetc(fin);
	}
	return x;
}

inline bool okay(int x){
	if (ok[x])
		return true;
	for (int i = 1; i <= n - x + 1; ++i)
		for (int j = 1; j <= n - x + 1; ++j)
			for (int k = 1; k <= n - x + 1; ++k)
				for (int l = 1; l <= n - x + 1; ++l){
					bool nok(true);
					for (int dx = 0; dx < x; ++dx){
						for (int dy = 0; dy < x; ++dy){
							int x1=i+dx,x2=k+dx,y1=j+dy,y2=l+dy;
							if (map1[x1][y1] != map2[x2][y2]){
								nok = false;
								break;
							}
							else
								ok[std::min(dx, dy) + 1] = true;
						if (! nok)
							break;
						}
					}
					if (nok)
						return ok[x] = true;
				}
	return false;
}