-
Notifications
You must be signed in to change notification settings - Fork 0
/
UVa10102.cpp
50 lines (49 loc) · 1017 Bytes
/
UVa10102.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
// shortcuts for "common" data types in contests
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000
int main()
{
int n;
while (scanf("%d\n", &n) != EOF)
{
vector<vi> field(n, vi(n));
vii ones, threes;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
int x; scanf("%1d", &x);
field.at(i).at(j) = x;
if (x == 1)
ones.push_back(make_pair(i, j));
else if (x == 3)
threes.push_back(make_pair(i, j));
}
}
int maxSteps = 0;
for (ii one : ones)
{
int minSteps = -1;
for (ii three : threes)
{
int dist = abs(one.first - three.first) + abs(one.second - three.second);
if (minSteps == -1) minSteps = dist;
else
minSteps = min(minSteps, dist);
}
maxSteps = max(maxSteps, minSteps);
}
printf("%d\n", maxSteps);
}
return 0;
}