Submission #22594

#TimeUsernameProblemLanguageResultExecution timeMemory
22594STARBUCKS (#40)Young Zebra (KRIII5_YZ)C++98
0 / 7
136 ms26576 KiB
#include <iostream> #include <algorithm> #include <cstdio> #include <vector> #include <utility> #include <string> #include <set> #include <map> using namespace std; char A[1303][1303]; int d[1303][1303]; int visit[1303][1303]; int dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int n, m; const int INF = 123456; int dfs(int x, int y, char c) { if(x == 0 || x == 3*n-1 || y == 0 || y == 3*m-1) return INF; if(visit[x][y]) return 0; if(d[x][y] != -2) return d[x][y]; visit[x][y] = 1; int ret = 0; for(int i=0; i<4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if(A[nx][ny] == c) ret += dfs(nx, ny, c); } // cout << x << ' ' << y << ' ' << ret + 1 << ' ' << endl; return d[x][y] = ret + 1; } void fill(int x, int y, char c, int ans) { if(x == 0 || x == 3*n-1 || y == 0 || y == 3*m-1) return; if(visit[x][y] == 2) return; visit[x][y] = 2; d[x][y] = ans; for(int i=0; i<4; i++) { int nx = x + dx[i]; int ny = y + dy[i]; if(A[nx][ny] == c) fill(nx, ny, c, ans); } } int main() { scanf("%d %d", &n, &m); for(int i=0; i<n; i++) { for(int j=0; j<m; j++) { scanf(" %c", &A[i][j]); for(int ii=0; ii<3; ii++) { for(int jj=0; jj<3; jj++) { A[n*ii+i][m*jj+j] = A[i][j]; d[n*ii+i][m*jj+j] = -2; } } } } for(int i=n; i<2*n; i++) { for(int j=m; j<2*m; j++) { int t = dfs(i, j, A[i][j]); fill(i, j, A[i][j], t); /*for(int ii=0; ii<3; ii++) { for(int jj=0; jj<3; jj++) { fill((ii-1)*n+i, (jj-1)*m+j, A[i][j], t); } }*/ printf("%d ", d[i][j] >= INF ? -1 : d[i][j]); // printf("%d ", t); } printf("\n"); } return 0; }

Compilation message (stderr)

YZ.cpp: In function 'int main()':
YZ.cpp:59: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:64:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &A[i][j]);
                          ^
#Verdict Execution timeMemoryGrader output
Fetching results...