Submission #22690

#TimeUsernameProblemLanguageResultExecution timeMemory
22690이대회 트래쉬 대회에야옹 (#40)Young Zebra (KRIII5_YZ)C++14
0 / 7
29 ms10496 KiB
#include <iostream> #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #include <vector> #include <stack> #include <queue> #include <functional> #include <map> #include <set> #include <string> using namespace std; int N, M; char sp[444][444]; int bcnt, wcnt; bool visit[444][444]; int ans[444][444]; int cnt; int mxcnt; char cur; int spx, spy; int an[444]; int idx = 1; void dfs(int, int); int main() { cin >> N >> M; for (int i = 0; i < N; i++) scanf("%s", sp[i]); for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { cnt = 0; mxcnt = 0; cur = sp[i][j]; if(!ans[i][j]) { dfs(i, j); an[idx++] = cnt; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { printf("%d ", an[ans[i][j]]); } printf("\n"); } } void dfs(int x, int y) { cnt++; visit[x][y] = true; if (x - 1 >= 0 && !visit[x - 1][y] && sp[x - 1][y] == cur) { dfs(x - 1, y); } if (x + 1 < N && !visit[x + 1][y] && sp[x + 1][y] == cur) { dfs(x + 1, y); } if (y - 1 >= 0 && !visit[x][y - 1] && sp[x][y - 1] == cur) { dfs(x, y - 1); } if (y + 1 < M && !visit[x][y + 1] && sp[x][y + 1] == cur) { dfs(x, y + 1); } if (x == 0 && !visit[N - 1][y] && sp[N - 1][y] == cur) dfs(N - 1, y); if (x == N - 1 && !visit[0][y] && sp[0][y] == cur) dfs(0, y); if (y == 0 && !visit[x][M - 1] && sp[x][M - 1] == cur) dfs(x, M - 1); if (y == M - 1 && !visit[x][0] && sp[x][0] == cur) dfs(x, 0); ans[x][y] = idx; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", sp[i]);
                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...