Submission #22463

#TimeUsernameProblemLanguageResultExecution timeMemory
22463카시코이 (#40)Young Zebra (KRIII5_YZ)C++98
0 / 7
86 ms113144 KiB
#include <cstdio> #include <vector> #include <queue> #include <set> #include <algorithm> using namespace std; int n, m; char board[2603][2603]; int visit[2603][2603]; int di[] = { 0, 1, 0, -1 }, dj[] = { 1, 0, -1, 0 }; int outlist[20000000]; int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { scanf(" %c", &board[i][j]); } } for (int i = n; i < n * 3; ++i) { for (int j = m; j < m * 3; ++j) { int bi = (i >= n * 2) ? i - n * 2 : i - n; int bj = (j >= m * 2) ? j - m * 2 : j - m; board[i][j] = board[bi][bj]; } } int cur = 0; for (int i = 0; i < 3 * n; ++i) { for (int j = 0; j < 3 * m; ++j) { if (visit[i][j] != 0) continue; ++cur; int cnt = 0; queue<pair<int, int> > q; visit[i][j] = cur; q.push(make_pair(i, j)); while (!q.empty()) { int ci = q.front().first, cj = q.front().second; q.pop(); ++cnt; for (int k = 0; k < 4; ++k) { int ni = ci + di[k], nj = cj + dj[k]; if (ni < 0 || ni >= n * 3 || nj < 0 || nj >= m * 3 || visit[ni][nj] != 0) continue; if (board[ni][nj] != board[i][j]) continue; visit[ni][nj] = cur; q.push(make_pair(ni, nj)); } } outlist[cur] = cnt; } } set<int> edgeset; for (int i = 0; i < n * 3; ++i) { edgeset.insert(visit[i][0]); edgeset.insert(visit[i][m * 3 - 1]); } for (int j = 0; j < m * 3; ++j) { edgeset.insert(visit[0][j]); edgeset.insert(visit[n * 3 - 1][j]); } for (int i = n; i < n * 2; ++i) { for (int j = m; j < m * 2; ++j) { int out = outlist[visit[i][j]]; if (edgeset.find(visit[i][j]) != edgeset.end()) out = -1; printf("%d", out); if (j < m * 2 - 1) printf(" "); } printf("\n"); } return 0; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:17:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
                        ^
YZ.cpp:20:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &board[i][j]);
                              ^
#Verdict Execution timeMemoryGrader output
Fetching results...