Submission #22691

#TimeUsernameProblemLanguageResultExecution timeMemory
22691최숭실 (#40)Young Zebra (KRIII5_YZ)C++11
0 / 7
159 ms74448 KiB
#include <cstdio> #define LIM 3 #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)

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