Pagini recente »
Istoria paginii runda/super-giga-maxim-simplu/clasament
|
Istoria paginii runda/s26_lab8_10/clasament
|
Monitorul de evaluare
|
rundaoni
|
Cod sursă (job #420641)
Cod sursă (job
#420641)
#include <bits/stdc++.h>
using namespace std;
int n, i, j, x, y, rx, ry, t[260000];
int dx[6] = {0, 1, 0, - 1, 1, - 1};
int dy[6] = {1, 0, - 1, 0, - 1, 1};
char a[510][510];
bool w[4][260000];
int rad(int x)
{
if (t[x] == 0) return x;
return t[x] = rad(t[x]);
}
int main()
{
ifstream cin("hex.in");
ofstream cout("hex.out");
cin >> n;
for (i = 1; i <= n * n; ++i)
{
cin >> x >> y;
rx = rad(x * (n + 1) + y);
if (x == 1)
w[0][rx] = 1;
if (x == n)
w[1][rx] = 1;
if (y == 1)
w[2][rx] = 1;
if (y == n)
w[3][rx] = 1;
a[x][y] = (i % 2) + 'a';
for (j = 0; j < 6; ++j)
if (a[x + dx[j]][y + dy[j]] == a[x][y])
{
ry = rad((x + dx[j]) * (n + 1) + y + dy[j]);
if (rx != ry)
{
t[ry] = rx;
for (int l = 0; l < 4; ++ l)
if (w[l][ry])
w[l][rx] = 1;
else if (w[l][rx])
w[l][ry] = 1;
}
}
if ((i % 2 == 0 && w[0][rx] && w[1][rx]) || (i % 2 && w[2][rx] && w[3][rx]))
{
cout << i;
return 0;
}
}
}