#include <cstdio>
#define LIM 0
#define EDGE_MIN (LIM - LIM)
#define EDGE_MAX (LIM * 2)
int n, m;
char map[410][410];
int check[410 * (LIM * 2+1)][410 * (LIM * 2 + 1)];
int id[410 * (LIM * 2 + 1)][410 * (LIM * 2 + 1)];
int count[410 * 410];
int xx[] = { 1,-1,0,0 };
int yy[] = { 0,0,1,-1 };
char get_col(int xi, int yi) {
return map[xi % n][yi % m];
}
int dfs(int xi, int yi, char col, int idx) {
if (id[xi][yi] != 0) return 0;
if(count[idx] != -1) count[idx]++;
id[xi][yi] = idx;
for (int i = 0; i < 4; i++) {
int ni = xi + xx[i], mi = yi + yy[i];
if (ni < 0) ni += n; if (ni >= n) ni -= n;
if (mi < 0) mi += m; if (mi >= m) mi -= m;
if (get_col(xi, yi) == get_col(ni, mi)) {
int val = dfs(ni, mi, col, idx);
if (val == -1) count[idx] = -1;
}
}
return 0;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", map[i]);
}
int myid = 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
dfs(i, j, map[i][j], myid++);
}
}
for (int i = 0; i < n; i++, printf("\n")) {
for (int j = 0; j < m; j++) {
printf("%d ", count[id[i][j]]);
}
}
}
Compilation message
YZ.cpp: In function 'int main()':
YZ.cpp:32:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
^
YZ.cpp:34:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", map[i]);
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
29 ms |
10256 KB |
Output is partially correct |
2 |
Partially correct |
23 ms |
9732 KB |
Output is partially correct |
3 |
Partially correct |
29 ms |
10000 KB |
Output is partially correct |
4 |
Partially correct |
23 ms |
5420 KB |
Output is partially correct |
5 |
Partially correct |
33 ms |
4860 KB |
Output is partially correct |
6 |
Partially correct |
29 ms |
3928 KB |
Output is partially correct |
7 |
Partially correct |
29 ms |
10412 KB |
Output is partially correct |
8 |
Partially correct |
26 ms |
11600 KB |
Output is partially correct |
9 |
Partially correct |
29 ms |
10408 KB |
Output is partially correct |
10 |
Partially correct |
29 ms |
9320 KB |
Output is partially correct |
11 |
Partially correct |
36 ms |
10868 KB |
Output is partially correct |
12 |
Partially correct |
36 ms |
14936 KB |
Output is partially correct |
13 |
Partially correct |
23 ms |
8840 KB |
Output is partially correct |
14 |
Partially correct |
33 ms |
7540 KB |
Output is partially correct |
15 |
Partially correct |
26 ms |
5152 KB |
Output is partially correct |
16 |
Partially correct |
23 ms |
7948 KB |
Output is partially correct |
17 |
Partially correct |
26 ms |
9292 KB |
Output is partially correct |
18 |
Partially correct |
29 ms |
9296 KB |
Output is partially correct |
19 |
Correct |
33 ms |
3248 KB |
Output is correct |
20 |
Partially correct |
29 ms |
6972 KB |
Output is partially correct |
21 |
Partially correct |
33 ms |
11352 KB |
Output is partially correct |
22 |
Partially correct |
29 ms |
9156 KB |
Output is partially correct |
23 |
Partially correct |
29 ms |
5292 KB |
Output is partially correct |
24 |
Partially correct |
26 ms |
5308 KB |
Output is partially correct |
25 |
Partially correct |
29 ms |
7764 KB |
Output is partially correct |
26 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
27 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
28 |
Partially correct |
0 ms |
3340 KB |
Output is partially correct |
29 |
Partially correct |
0 ms |
3344 KB |
Output is partially correct |
30 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
31 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
32 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
33 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
34 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
35 |
Partially correct |
0 ms |
3248 KB |
Output is partially correct |
36 |
Partially correct |
0 ms |
3688 KB |
Output is partially correct |
37 |
Partially correct |
0 ms |
3432 KB |
Output is partially correct |
38 |
Correct |
0 ms |
3248 KB |
Output is correct |
39 |
Partially correct |
0 ms |
3460 KB |
Output is partially correct |
40 |
Partially correct |
0 ms |
3612 KB |
Output is partially correct |