# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22695 | 최숭실 (#40) | Young Zebra (KRIII5_YZ) | C++11 | 500 ms | 148804 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 <cstdio>
#define LIM 4
#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 (xi / n == EDGE_MIN || xi / n == EDGE_MAX ||
yi / m == EDGE_MAX || yi / m == EDGE_MIN) {
return -1;
}
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 (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 + n*LIM, j + m*LIM, 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+n*LIM][j+m*LIM]]);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |