# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22825 | STARBUCKS (#40) | Young Zebra (KRIII5_YZ) | C++98 | 99 ms | 16944 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
char A[1303][1303];
int d[1303][1303];
int visit[1303][1303];
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
int n, m;
#define x first
#define y second
int get(int x, int y)
{
queue< pair<int, int> > Q;
int r = 0;
int INF = 0;
Q.push({x, y});
while(Q.size())
{
pair<int, int> cur = Q.front(); Q.pop();
int outside = cur.x < 0 || cur.x >= 3*n-1 || cur.y < 0 || cur.y >= 3*m-1;
if(outside)
{
continue;
}
if(visit[cur.x][cur.y]) continue;
visit[cur.x][cur.y] = 1;
r++;
int border = cur.x == 0 || cur.x == 3*n-1 || cur.y == 0 || cur.y == 3*m-1;
if(border)
{
INF = 1;
}
for(int i=0; i<4; i++)
{
int nx = cur.x + dx[i];
int ny = cur.y + dy[i];
if(visit[nx][ny] == 0 && A[nx][ny] == A[x][y])
{
Q.push({nx, ny});
}
}
}
return INF ? 1e9 : r;
}
void fill(int x, int y, int ans)
{
queue< pair<int, int> > Q;
Q.push({x, y});
while(Q.size())
{
pair<int, int> cur = Q.front(); Q.pop();
int outside = cur.x < 0 || cur.x >= 3*n-1 || cur.y < 0 || cur.y >= 3*m-1;
if(outside)
{
continue;
}
if(d[cur.x][cur.y] != -2) continue;
d[cur.x][cur.y] = ans;
for(int i=0; i<4; i++)
{
int nx = cur.x + dx[i];
int ny = cur.y + dy[i];
if(d[nx][ny] == -2 && A[nx][ny] == A[x][y])
{
Q.push({nx, ny});
}
}
}
}
int main()
{
scanf("%d %d", &n, &m);
for(int i=0; i<n; i++)
{
scanf("%s", A[i]);
for(int j=0; j<m; j++)
{
// A[i][j] = 'A';
// if(i == 0 || j == 0 || i == n-1 || j == m-1 || i == n/2) A[i][j] += 1;
for(int ii=0; ii<3; ii++)
{
for(int jj=0; jj<3; jj++)
{
A[n*ii+i][m*jj+j] = A[i][j];
d[n*ii+i][m*jj+j] = -2;
}
}
}
}
for(int i=n; i<2*n; i++)
{
for(int j=m; j<2*m; j++)
{
if(d[i][j] != -2)
{
// nothing
}
else
{
int t = get(i, j);
for(int ii=0; ii<3; ii++)
{
for(int jj=0; jj<3; jj++)
{
fill((ii-1)*n+i, (jj-1)*m+j, t);
}
}
}
printf("%d ", d[i][j] >= 1e9 ? -1 : d[i][j]);
} printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |