답안 #22863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22863 2017-04-30T07:53:52 Z STARBUCKS(#950, hichoe95, exqt, kshy9598) Young Zebra (KRIII5_YZ) C++
0 / 7
146 ms 16944 KB
#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)
        {
            INF = 1;
            continue;
        }

        if(visit[cur.x][cur.y]) continue;
        visit[cur.x][cur.y] = 1;
        r++;

        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=0; i<3*n; i++)
    {
        for(int j=0; j<3*m; j++)
        {
            if(d[i][j] == -2)
            {
                int t = get(i, j);
                fill(i, j, t);
            }

            if(n<=i && i<2*n && m<=j && j<2*m) printf("%d ", d[i][j] > 1e8 ? -1 : d[i][j]);
        }
        if(n<=i && i<2*n) printf("\n");
    }

	return 0;
}

Compilation message

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:45:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                        ^
YZ.cpp:45: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:57:12: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
            ^
YZ.cpp:57:18: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
     Q.push({x, y});
                  ^
YZ.cpp:78:24: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11
                 Q.push({nx, ny});
                        ^
YZ.cpp:78: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:86: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:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%s", A[i]);
                       ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 146 ms 16944 KB Output is partially correct
2 Incorrect 136 ms 16944 KB Output isn't correct
3 Halted 0 ms 0 KB -