Submission #22812

# Submission time Handle Problem Language Result Execution time Memory
22812 2017-04-30T07:38:05 Z STARBUCKS(#950, hichoe95, exqt, kshy9598) Young Zebra (KRIII5_YZ) C++
0 / 7
96 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();
        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 ? 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.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++)
	{
	    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++)
		{
		    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] >= 1e9 ? -1 : d[i][j]);
		} 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: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:87:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
      scanf("%s", A[i]);
                       ^
# Verdict Execution time Memory Grader output
1 Partially correct 83 ms 16944 KB Output is partially correct
2 Incorrect 96 ms 16944 KB Output isn't correct
3 Halted 0 ms 0 KB -