# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22631 | 최숭실 (#40) | Young Zebra (KRIII5_YZ) | C++14 | 500 ms | 362916 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<iostream>
using namespace std;
char Dy[8410][8410];
int visit[8410][8410];
char Data[410][410];
int ans[410][410];
int dir[4][2] = { 0,1,1,0,0,-1,-1,0 };
int num = 1;
int cnt[160010];
int flag = 0;
int n, m;
void dfs(int y, int x, char base)
{
for (int i = 0; i < 4; i++)
{
if (y + dir[i][0] == 0)
{
flag = 1;
continue;
}
if (y + dir[i][0] == 21 * n)
{
flag = 1;
continue;
}
if (x + dir[i][1] == 0)
{
flag = 1;
continue;
}
if (x + dir[i][1] == 21 * m)
{
flag = 1;
continue;
}
if (Dy[y + dir[i][0]][x + dir[i][1]] == base && visit[y + dir[i][0]][x + dir[i][1]] == 0)
{
cnt[num]++;
visit[y + dir[i][0]][x + dir[i][1]] = num;
dfs(y + dir[i][0], x + dir[i][1], base);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
cin >> Data[i][j];
int start_n = 10 * n;
int start_m = 10 * m;
for (int i = 0; i < 21 * n; i++)
for (int j = 0; j < 21 * m; j++)
Dy[i][j] = Data[i%n][j%m];
for (int i = start_n; i < start_n + n; i++)
{
for (int j = start_m; j < start_m + m; j++)
{
flag = 0;
if (visit[i][j] != 0)continue;
cnt[num]++;
visit[i][j] = num;
dfs(i, j, Dy[i][j]);
if (flag)
cnt[num] = -1;
num++;
}
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
//cout << cnt[visit[i + start_n][j + start_m]] << " ";
printf("%d ", cnt[visit[i + start_n][j + start_m]]);
}
if (i != n - 1)
printf("\n");
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |