# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22830 | dried chocochip on Daegu asphalt (#40) | Young Zebra (KRIII5_YZ) | C++11 | 43 ms | 11076 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};
int mod(int val, int m)
{
while(val < 0)
val += m*m*m;
return val%m;
}
int si, sj;
bool cc_inf[400*400+2];
void dfs(int i, int j)
{
int ii = mod(i, n), jj = mod(j, m);
visited[ii][jj] = true;
cc[ii][jj] = c_idx;
cc_sz[c_idx]++;
for(int k = 0; k < 4; k++)
{
int ni = i+di[k], nj = j+dj[k];
int nii = mod(ni, n), njj = mod(nj, m);
if(!(si == ni && sj == nj))
if(si == nii && sj == njj)
cc_inf[c_idx] = true;
if(!visited[nii][njj] && mmap[ii][jj] == mmap[nii][njj])
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])
{
si = i, sj = j;
c_idx++;
dfs(i, j);
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
printf("%d ", cc_inf[cc[i][j]] ? -1 : cc_sz[cc[i][j]]);
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |