Submission #22831

#TimeUsernameProblemLanguageResultExecution timeMemory
22831STARBUCKS (#40)Young Zebra (KRIII5_YZ)C++98
0 / 7
449 ms16944 KiB
#include <bits/stdc++.h> 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; #define x first #define y second int get(int x, int y) { queue< pair<int, int> > Q; int r = 0; int INF = 0; Q.push({x, y}); while(Q.size()) { pair<int, int> cur = Q.front(); Q.pop(); int outside = cur.x < 0 || cur.x >= 3*n-1 || cur.y < 0 || cur.y >= 3*m-1; if(outside) { continue; } if(visit[cur.x][cur.y]) continue; visit[cur.x][cur.y] = 1; r++; int border = cur.x == 0 || cur.x == 3*n-1 || cur.y == 0 || cur.y == 3*m-1; if(border) { INF = 1; } for(int i=0; i<4; i++) { int nx = cur.x + dx[i]; int ny = cur.y + dy[i]; if(visit[nx][ny] == 0 && A[nx][ny] == A[x][y]) { Q.push({nx, ny}); } } } return INF ? 1e9 : r; } void fill(int x, int y, int ans) { queue< pair<int, int> > Q; Q.push({x, y}); while(Q.size()) { pair<int, int> cur = Q.front(); Q.pop(); int outside = cur.x < 0 || cur.x >= 3*n-1 || cur.y < 0 || cur.y >= 3*m-1; if(outside) { continue; } if(d[cur.x][cur.y] != -2) continue; d[cur.x][cur.y] = ans; for(int i=0; i<4; i++) { int nx = cur.x + dx[i]; int ny = cur.y + dy[i]; if(d[nx][ny] == -2 && A[nx][ny] == A[x][y]) { Q.push({nx, ny}); } } } } int main() { scanf("%d %d", &n, &m); for(int i=0; i<n; i++) { scanf("%s", A[i]); for(int j=0; j<m; j++) { // A[i][j] = 'A'; // if(i == 0 || j == 0 || i == n-1 || j == m-1 || i == n/2) A[i][j] += 1; 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++) { for(int ii=0; ii<3; ii++) { for(int jj=0; jj<3; jj++) { int t = d[(ii-1)*n+i][(jj-1)*m+j]; if(t == -2) t = get((ii-1)*n+i, (jj-1)*m+j); fill((ii-1)*n+i, (jj-1)*m+j, t); } } printf("%d ", d[i][j] >= 1e9 ? -1 : d[i][j]); } printf("\n"); } return 0; }

Compilation message (stderr)

YZ.cpp: In function 'int get(int, int)':
YZ.cpp:21:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
            ^
YZ.cpp:21:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
                  ^
YZ.cpp:50:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                        ^
YZ.cpp:50:32: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                                ^
YZ.cpp: In function 'void fill(int, int, int)':
YZ.cpp:62:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
            ^
YZ.cpp:62:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
                  ^
YZ.cpp:83:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                        ^
YZ.cpp:83:32: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                                ^
YZ.cpp: In function 'int main()':
YZ.cpp:91: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:94:23: 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...