# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22427 | ↓우리보다잘하는팀 (#40) | Young Zebra (KRIII5_YZ) | C++98 | 36 ms | 12428 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>
int n, m;
char s[410][410];
int chk[410][410];
int dim[410][410][2];
int ans[410][410];
int cn;
int scon;
int con[200100][2];
void dfs(int x, int y, int px, int py, char z) {
if (x < 0) {
dfs(x + n, y, px - 1, py, z);
return;
}
if (x >= n) {
dfs(x - n, y, px + 1, py, z);
return;
}
if (y < 0) {
dfs(x, y + m, px, py - 1, z);
return;
}
if (y >= m) {
dfs(x, y - m, px, py + 1, z);
return;
}
if (s[x][y] != z)return;
if (chk[x][y] != 0) {
if (px == dim[x][y][0] && py == dim[x][y][1])return;
scon = 1;
return;
}
chk[x][y] = 1;
con[cn][0] = x;
con[cn][1] = y;
cn++;
dim[x][y][0] = px;
dim[x][y][1] = py;
dfs(x + 1, y, px, py, z);
dfs(x - 1, y, px, py, z);
dfs(x, y + 1, px, py, z);
dfs(x, y - 1, px, py, z);
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%s", s[i]);
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (chk[i][j] == 0) {
cn = 0;
scon = 0;
dfs(i, j, 0, 0, s[i][j]);
for (int k = 0; k < cn; k++) {
if (scon)ans[con[k][0]][con[k][1]] = -1;
else ans[con[k][0]][con[k][1]] = cn;
}
}
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
printf("%d ", ans[i][j]);
}
printf("\n");
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |