제출 #22573

#제출 시각아이디문제언어결과실행 시간메모리
22573Lazy Against The Machine (#40)Young Zebra (KRIII5_YZ)C++14
7 / 7
33 ms16192 KiB
#include <bits/stdc++.h> using namespace std; char dat[404][404]; bool visit[404][404]; int ans[404][404]; pair<int, int> depth[404][404]; vector<pair<int, int>> components; bool infinite; int n, m; int dr[4][2] = { 1, 0, 0, 1, -1, 0, 0, -1 }; void dfs(int x, int y, int dx, int dy) { visit[x][y] = true; depth[x][y] = {dx, dy}; components.emplace_back(x, y); for (int i = 0; i < 4; i++) { int nx = x + dr[i][0]; int ny = y + dr[i][1]; int ndx = dx, ndy = dy; if (nx < 0) { --ndx; nx += n; } if (nx >= n) { ++ndx; nx -= n; } if (ny < 0) { --ndy; ny += m; } if (ny >= m) { ++ndy; ny -= m; } if (dat[x][y] != dat[nx][ny]) continue; if (visit[nx][ny]) { if (depth[nx][ny] != make_pair(ndx, ndy)) infinite = true; continue; } dfs(nx, ny, ndx, ndy); } } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { scanf("%s", dat[i]); } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { if (visit[i][j]) continue; infinite = false; components.clear(); dfs(i, j, 0, 0); for (auto &e : components) { if (infinite) ans[e.first][e.second] = -1; else ans[e.first][e.second] = components.size(); } } } for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) printf("%d ", ans[i][j]); printf("\n"); } }

컴파일 시 표준 에러 (stderr) 메시지

YZ.cpp: In function 'int main()':
YZ.cpp:68:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
                          ^
YZ.cpp:72:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", dat[i]);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...