10102

Critical t get the question but easy to solve. Problem asks to find the maximum length of minimum distance.

#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <cmath>
#include <cstring>
#include <fstream>
#include <string>
#include <algorithm>

#define INF 100000000
#define ll long long

using namespace std;

struct Cord{
	int x,y;
};
int M;
char gr[1010][1010];
char s[1010][1010];
vector<Cord> Ones,Threes;

int main()
{
	Cord tmp;
	int MX,dist,MN;
	while(scanf("%d",&M)!=EOF)
	{
		getchar();
		Threes.clear();
		Ones.clear();
		for(int i=0;i<M;i++)
		{
			scanf("%s",s[i]);
			for(int j=0;j<strlen(s[i]);j++)
			{
				if(s[i][j]=='1')
				{
					tmp.x = i;
					tmp.y = j;
					Ones.push_back(tmp);
				}
				if(s[i][j]=='3')
				{
					tmp.x = i;
					tmp.y = j;
					Threes.push_back(tmp);
				}
			}
		}
		MX = -1;
		for(int i=0;i<Ones.size();i++)
		{
			MN = INF;
			for(int j=0;j<Threes.size();j++)
			{
				dist = abs(Ones[i].x-Threes[j].x)+abs(Ones[i].y-Threes[j].y);
				if(dist<MN)
				MN =dist;
			}
			if(MX<MN)
			MX = MN;
		}
		printf("%d\n",MX);
	}
	return 0;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *