Submission #22797

#TimeUsernameProblemLanguageResultExecution timeMemory
22797STARBUCKS (#40)Young Zebra (KRIII5_YZ)C++98
0 / 7
93 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(); 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.x == 0 || cur.x == 3*m-1; if(border) { INF = 1; continue; } 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 ? 2e6 : 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.x < 0 || cur.x >= 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++) { 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++) { if(d[i][j] != -2) { // nothing } else { int t = get(i, j); for(int ii=0; ii<3; ii++) { for(int jj=0; jj<3; jj++) { fill((ii-1)*n+i, (jj-1)*m+j, t); } } } printf("%d ", d[i][j] >= 2e6 ? -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:44:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                        ^
YZ.cpp:44: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:55:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
            ^
YZ.cpp:55:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
                  ^
YZ.cpp:76:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                        ^
YZ.cpp:76: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:84: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:89: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...