Submission #22939

#TimeUsernameProblemLanguageResultExecution timeMemory
22939cprayerYoung Zebra (KRIII5_YZ)C++14
0 / 7
173 ms32708 KiB
#include <cstdio> #include <vector> #include <algorithm> using namespace std; const int MAXN = 409, MAXM = 409; const int cx[] = {1, 0, -1 ,0}, cy[] = {0, 1, 0, -1}; char A[MAXN * 3][MAXN * 3]; int ans[MAXN * 3][MAXN * 3], visited[MAXN * 3][MAXN * 3]; bool visited2[MAXN * 3][MAXN * 3]; int N, M, cnt, inf; vector<pair<int, int>> path; int dfs1(int y, int x, char c){ if(y >= N * 3) y = 0; if(y < 0) y = N * 3; if(x >= M * 3) x = 0; if(x < 0) x = M * 3; if(visited[y][x] || A[y][x] != c) return 0; int res = 1; visited[y][x] = cnt; for(int i = 0; i < 4; i++) res += dfs1(y + cy[i], x + cx[i], c); return res; } void dfs2(int y, int x, char c){ if(y >= N * 3) y = 0; if(y < 0) y = N * 3; if(x >= M * 3) x = 0; if(x < 0) x = M * 3; if((y / N != 1 || x / M != 1) && visited[y][x] == cnt && visited[y][x] == visited[N + y % N][M + x % M]) inf = true; if(visited2[y][x] || A[y][x] != c) return; path.push_back({y, x}); visited2[y][x] = true; for(int i = 0; i < 4; i++) dfs2(y + cy[i], x + cx[i], c); } int main(){ scanf("%d%d%*c", &N, &M); for(int i = 0; i < N; i++){ scanf("%s", A[i]); for(int j = 0; j < M; j++){ for(int v = 0; v < 3; v++){ for(int w = 0; w < 3; w++) A[v * N + i][w * M + j] = A[i][j]; } } } for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++){ int y = i + N, x = j + M; if(!visited[y][x]){ inf = 0; cnt++; int v = dfs1(y, x, A[y][x]); dfs2(y, x, A[y][x]); if(inf) v = -1; for(auto l : path) ans[l.first][l.second] = v; path.clear(); } } } for(int i = 0; i < N; i++){ for(int j = 0; j < M; j++) printf("%d ", ans[i + N][j + M]); printf("\n"); } }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:40:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%*c", &N, &M);
                             ^
YZ.cpp:42:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s", A[i]);
                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...