Submission #22786

#TimeUsernameProblemLanguageResultExecution timeMemory
22786이대회 트래쉬 대회에야옹 (#40)Young Zebra (KRIII5_YZ)C++14
0 / 7
26 ms11264 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][5]; int ans[444][444]; int cnt; int mxcnt; char cur; int spx, spy; int an[444]; int idx = 1; bool chk; void dfs(int, int, int); int main() { cin >> N >> M; for (int i = 0; i < N; i++) { scanf("%s", sp[i]); for (int j = 0; sp[i][j] != 0; j++) sp[i][j] == 'W' ? wcnt++ : bcnt++; } 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, 0); an[idx++] = cnt; } } } for (int i = 0; i < N; i++) { for (int j = 0; j < M; j++) { if (sp[i][j] == 'B' && an[ans[i][j]] > bcnt) printf("-1 "); if (sp[i][j] == 'W' && an[ans[i][j]] > wcnt) printf("-1 "); else printf("%d ", an[ans[i][j]]); } printf("\n"); } } void dfs(int x, int y, int dir) { cnt++; visit[x][y][0] = true; if (chk) visit[x][y][1] = true; if (x - 1 >= 0 && !visit[x - 1][y][dir] && sp[x - 1][y] == cur) { dfs(x - 1, y, dir); } if (x + 1 < N && !visit[x + 1][y][dir] && sp[x + 1][y] == cur) { dfs(x + 1, y, dir); } if (y - 1 >= 0 && !visit[x][y - 1][dir] && sp[x][y - 1] == cur) { dfs(x, y - 1, dir); } if (y + 1 < M && !visit[x][y + 1][dir] && sp[x][y + 1] == cur) { dfs(x, y + 1, dir); } if (x == 0 && !visit[N - 1][y][0] && !visit[N - 1][y][1] && sp[N - 1][y] == cur) { chk = true; dfs(N - 1, y, 0); chk = false; } if (x == N - 1 && !visit[0][y][0] && !visit[0][y][1] && sp[0][y] == cur) { chk = true; dfs(0, y, 0); chk = false; } if (y == 0 && !visit[x][M - 1][0] && !visit[x][M - 1][1] && sp[x][M - 1] == cur) { chk = true; dfs(x, M - 1, 0); chk = false; } if (y == M - 1 && !visit[x][0][0] && !visit[x][0][1] && sp[x][0] == cur) { chk = true; dfs(x, 0, 0); chk = false; } ans[x][y] = idx; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:36: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...