Submission #22427

#TimeUsernameProblemLanguageResultExecution timeMemory
22427↓우리보다잘하는팀 (#40)Young Zebra (KRIII5_YZ)C++98
7 / 7
36 ms12428 KiB
#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)

YZ.cpp: In function 'int main()':
YZ.cpp:45: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:47:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s[i]);
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...