#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};
char mmap2[2000][2000];
int cc2[2000][2000], c_idx2;
bool visited2[2000][2000];
int cc_sz2[2000*2000+2];
void dfs2(int i, int j)
{
visited2[i][j] = true;
cc2[i][j] = c_idx2;
cc_sz2[c_idx]++;
for(int k = 0; k < 4; k++)
{
int ni = i+di[k], nj = j+dj[k];
if(ni < 0 || ni >= 5*n || nj < 0 || nj >= 5*m) continue;
if(!visited2[ni][nj] && mmap2[i][j] == mmap2[ni][nj])
dfs2(ni, nj);
}
}
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 < 5*n; i++)
for(int j = 0; j < 5*m; j++)
mmap2[i][j] = mmap[i%n][j%m];
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 < 5*n; i++)
for(int j = 0; j < 5*m; j++)
if(!visited2[i][j])
{
c_idx2++;
dfs2(i, j);
}
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
bool check = false;
for(int ddi = 0; ddi < 5; ddi++)
for(int ddj = 0; ddj < 5; ddj++)
{
if(ddi == 2 && ddj == 2) continue;
if(cc2[i+n*2][j+m*2] == cc2[i+ddi*n][j+ddj*m])
check = true;
}
if(check) printf("-1 ");
else printf("%d ", cc_sz[cc[i][j]]);
}
printf("\n");
}
return 0;
}
Compilation message
YZ.cpp: In function 'int main()':
YZ.cpp:54:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
^
YZ.cpp:57:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf(" %c", &mmap[i][j]);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
219 ms |
52688 KB |
Output is partially correct |
2 |
Partially correct |
226 ms |
54284 KB |
Output is partially correct |
3 |
Partially correct |
186 ms |
47332 KB |
Output is partially correct |
4 |
Correct |
209 ms |
48468 KB |
Output is correct |
5 |
Correct |
213 ms |
48416 KB |
Output is correct |
6 |
Correct |
193 ms |
47032 KB |
Output is correct |
7 |
Partially correct |
233 ms |
46892 KB |
Output is partially correct |
8 |
Partially correct |
123 ms |
44420 KB |
Output is partially correct |
9 |
Partially correct |
249 ms |
46888 KB |
Output is partially correct |
10 |
Partially correct |
173 ms |
44412 KB |
Output is partially correct |
11 |
Correct |
279 ms |
49984 KB |
Output is correct |
12 |
Correct |
279 ms |
49980 KB |
Output is correct |
13 |
Partially correct |
259 ms |
46720 KB |
Output is partially correct |
14 |
Partially correct |
169 ms |
45940 KB |
Output is partially correct |
15 |
Partially correct |
236 ms |
43952 KB |
Output is partially correct |
16 |
Partially correct |
169 ms |
45516 KB |
Output is partially correct |
17 |
Correct |
176 ms |
61036 KB |
Output is correct |
18 |
Correct |
163 ms |
61032 KB |
Output is correct |
19 |
Correct |
243 ms |
42644 KB |
Output is correct |
20 |
Correct |
279 ms |
121060 KB |
Output is correct |
21 |
Partially correct |
223 ms |
47456 KB |
Output is partially correct |
22 |
Partially correct |
243 ms |
47344 KB |
Output is partially correct |
23 |
Correct |
263 ms |
109668 KB |
Output is correct |
24 |
Correct |
233 ms |
100268 KB |
Output is correct |
25 |
Partially correct |
309 ms |
45020 KB |
Output is partially correct |
26 |
Correct |
0 ms |
42644 KB |
Output is correct |
27 |
Correct |
0 ms |
42644 KB |
Output is correct |
28 |
Correct |
6 ms |
45808 KB |
Output is correct |
29 |
Correct |
0 ms |
45800 KB |
Output is correct |
30 |
Correct |
0 ms |
42644 KB |
Output is correct |
31 |
Correct |
0 ms |
42644 KB |
Output is correct |
32 |
Correct |
0 ms |
42644 KB |
Output is correct |
33 |
Correct |
0 ms |
42644 KB |
Output is correct |
34 |
Correct |
0 ms |
42644 KB |
Output is correct |
35 |
Correct |
0 ms |
42644 KB |
Output is correct |
36 |
Correct |
13 ms |
54264 KB |
Output is correct |
37 |
Correct |
16 ms |
50168 KB |
Output is correct |
38 |
Correct |
16 ms |
42644 KB |
Output is correct |
39 |
Correct |
13 ms |
49616 KB |
Output is correct |
40 |
Correct |
9 ms |
54344 KB |
Output is correct |