记录编号 370475 评测结果 AAAAAAAA
题目名称 城堡 最终得分 100
用户昵称 GravatarMealy 是否通过 通过
代码语言 C++ 运行时间 0.004 s
提交时间 2017-02-13 20:43:41 内存使用 34.67 MiB
显示代码纯文本
//671
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
const int nmax=3000;
int n,m;

int num;
int maxroom;
int moveroom;
char movewall;
int mx;
int my;

int res[nmax][nmax]={0};
class UFS{
public:
	int f[nmax];
	int size[nmax];
	void Init(int n){
		for(int i=1;i<=n;i++){
			f[i]=i;
			size[i]=1;
		}
	}
	int Find(int x){
		if(x==f[x]){
			return x;
		}
		return Find(f[x]);
	}
	void Merge(int a,int b){
		int fa=Find(a);
		int fb=Find(b);
		f[fa]=fb;
		size[fb]+=size[fa];
	}
}FJ;
int Idx(int x,int y){
	return (x-1)*m+y;
}
bool Check(int i,int j){
	if(i>=1&&i<=n&&j>=1&&j<=m){
		return 1;
	}
	return 0;
}
void PreDo(){
	scanf("%d%d",&m,&n);
	FJ.Init(n*m);
	num=n*m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			scanf("%d",&res[i][j]);
			for(int k=0;k<=3;k++){
				if(!((1<<k)&res[i][j])){
					if(k==0){
						if(Check(i,j-1)){
							if(FJ.Find(Idx(i,j-1))!=FJ.Find(Idx(i,j))){
								FJ.Merge(Idx(i,j-1),Idx(i,j));
								num--;
							}
						}
					}
					if(k==1){
						if(Check(i-1,j)){
							if(FJ.Find(Idx(i-1,j))!=FJ.Find(Idx(i,j))){
								FJ.Merge(Idx(i-1,j),Idx(i,j));
								num--;
							}
						}
					}
					if(k==2){
						if(Check(i,j+1)){
							if(FJ.Find(Idx(i,j+1))!=FJ.Find(Idx(i,j))){
								FJ.Merge(Idx(i,j+1),Idx(i,j));
								num--;
							}
						}
					}
					if(k==3){
						if(Check(i+1,j)){
							if(FJ.Find(Idx(i+1,j))!=FJ.Find(Idx(i,j))){
								FJ.Merge(Idx(i+1,j),Idx(i,j));
								num--;
							}
						}
					}
				}
			}					
		}
	}
	printf("%d\n",num);
	for(int i=1;i<=n*m;i++){
		maxroom=max(maxroom,FJ.size[i]);
	}
	printf("%d\n",maxroom);
}
void Col(){
	for(int j=1;j<=m;j++){
		for(int i=n;i>=1;i--){
			for(int k=1;k<=2;k++){
				if(((1<<k)&res[i][j])){
					if(k==1){
						if(Check(i-1,j)){
							if(FJ.Find(Idx(i-1,j))!=FJ.Find(Idx(i,j))){
								if(FJ.size[FJ.Find(Idx(i-1,j))]+FJ.size[FJ.Find(Idx(i,j))]>moveroom){
									moveroom=FJ.size[FJ.Find(Idx(i-1,j))]+FJ.size[FJ.Find(Idx(i,j))];
									mx=i;
									my=j;
									movewall='N';
								}
							}
						}
					}
					if(k==2){
						if(Check(i,j+1)){
							if(FJ.Find(Idx(i,j+1))!=FJ.Find(Idx(i,j))){
								if(FJ.size[FJ.Find(Idx(i,j+1))]+FJ.size[FJ.Find(Idx(i,j))]>moveroom){
									moveroom=FJ.size[FJ.Find(Idx(i,j+1))]+FJ.size[FJ.Find(Idx(i,j))];
									mx=i;
									my=j;
									movewall='E';
								}
							}
						}
					}
				}
			}
		}
	}
	printf("%d\n",moveroom);
	printf("%d %d %c",mx,my,movewall);
}
int main(){
	freopen("castle.in","r",stdin);
	freopen("castle.out","w",stdout);
	PreDo();
	Col();
	return 0;
}