# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22644 | dried chocochip on Daegu asphalt (#40) | Young Zebra (KRIII5_YZ) | C++11 | 33 ms | 10916 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;
int n, m;
char mmap[400][400];
int cc[400][400], c_idx;
bool visited[400][400];
int cc_sz[400*400+2];
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};
void dfs(int i, int j)
{
visited[i][j] = true;
cc[i][j] = c_idx;
cc_sz[c_idx]++;
for(int k = 0; k < 4; k++)
{
int ni = i+di[k], nj = j+dj[k];
if(ni < 0) ni += n;
if(ni >= n) ni -= n;
if(nj < 0) nj += m;
if(nj >= m) nj -= m;
if(!visited[ni][nj] && mmap[i][j] == mmap[ni][nj])
dfs(ni, nj);
}
}
int main()
{
scanf("%d %d", &n, &m);
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
scanf(" %c", &mmap[i][j]);
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
if(!visited[i][j])
{
c_idx++;
dfs(i, j);
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
printf("%d ", cc_sz[cc[i][j]]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |