# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22680 | 이대회 트래쉬 대회에야옹 (#40) | Young Zebra (KRIII5_YZ) | C++14 | 26 ms | 10164 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>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <string>
using namespace std;
int N, M;
char sp[444][444];
int bcnt, wcnt;
bool visit[444][444];
int ans[444][444];
int cnt;
int mxcnt;
char cur;
int spx, spy;
int an[444];
int idx = 1;
void dfs(int, int);
int main()
{
cin >> N >> M;
for (int i = 0; i < N; i++)
scanf("%s", sp[i]);
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
cnt = 0;
mxcnt = 0;
cur = sp[i][j];
if(!ans[i][j])
{
dfs(i, j);
an[idx++] = cnt;
}
}
}
for (int i = 0; i < N; i++)
{
for (int j = 0; j < M; j++)
{
printf("%d ", an[ans[i][j]]);
}
printf("\n");
}
}
void dfs(int x, int y)
{
cnt++;
visit[x][y] = true;
if (x == 0 && !visit[N - 1][y] && sp[N - 1][y] == cur)
dfs(N - 1, y);
if (x == N - 1 && !visit[0][y] && sp[0][y] == cur)
dfs(0, y);
if (y == 0 && !visit[x][M - 1] && sp[x][M - 1] == cur)
dfs(x, M - 1);
if (y == M - 1 && !visit[x][0] && sp[x][0] == cur)
dfs(x, 0);
if (x - 1 >= 0 && !visit[x - 1][y] && sp[x - 1][y] == cur)
{
dfs(x - 1, y);
}
if (x + 1 < N && !visit[x + 1][y] && sp[x + 1][y] == cur)
{
dfs(x + 1, y);
}
if (y - 1 >= 0 && !visit[x][y - 1] && sp[x][y - 1] == cur)
{
dfs(x, y - 1);
}
if (y + 1 < M && !visit[x][y + 1] && sp[x][y + 1] == cur)
{
dfs(x, y + 1);
}
ans[x][y] = idx;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |