Submission #22715

# Submission time Handle Problem Language Result Execution time Memory
22715 2017-04-30T06:50:13 Z dried chocochip on Daegu asphalt(#897, suzy, zych1751, Acka) Young Zebra (KRIII5_YZ) C++11
0 / 7
500 ms 165112 KB
#include<bits/stdc++.h>

using namespace std;

int n, m;
char mmap[400][400];
int cc[400][400], c_idx;
bool visited[400][400];
int cc_sz[400*400+2];
int di[4] = {-1, 0, 1, 0};
int dj[4] = {0, 1, 0, -1};

char mmap2[2800][2800];
int cc2[2800][2800], c_idx2;
bool visited2[2800][2800];

void dfs2(int i, int j)
{
	visited2[i][j] = true;
	cc2[i][j] = c_idx2;

	for(int k = 0; k < 4; k++)
	{
		int ni = i+di[k], nj = j+dj[k];
		if(ni < 0 || ni >= 7*n || nj < 0 || nj >= 7*m)	continue;
		if(!visited2[ni][nj] && mmap2[i][j] == mmap2[ni][nj])
			dfs2(ni, nj);
	}
}

void dfs(int i, int j)
{
	visited[i][j] = true;
	cc[i][j] = c_idx;
	cc_sz[c_idx]++;

	for(int k = 0; k < 4; k++)
	{
		int ni = i+di[k], nj = j+dj[k];
		if(ni < 0)	ni += n;
		if(ni >= n)	ni -= n;
		if(nj < 0)	nj += m;
		if(nj >= m)	nj -= m;

		if(!visited[ni][nj] && mmap[i][j] == mmap[ni][nj])
			dfs(ni, nj);
	}
}

int main()
{
	scanf("%d %d", &n, &m);
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			scanf(" %c", &mmap[i][j]);

	for(int i = 0; i < 7*n; i++)
		for(int j = 0; j < 7*m; j++)
			mmap2[i][j] = mmap[i%n][j%m];

	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			if(!visited[i][j])
			{
				c_idx++;
				dfs(i, j);
			}

	for(int i = 0; i < 7*n; i++)
		for(int j = 0; j < 7*m; j++)
			if(!visited2[i][j])
			{
				c_idx2++;
				dfs2(i, j);
			}
	

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
		{
			bool check = false;
			for(int ddi = 0; ddi < 7; ddi++)
				for(int ddj = 0; ddj < 7; ddj++)
				{
					if(ddi == 3 && ddj == 3)	continue;
					if(cc2[i+n*3][j+m*3] == cc2[i+ddi*n][j+ddj*m])
						check = true;
				}
			if(check)	printf("-1 ");
			else	printf("%d ", cc_sz[cc[i][j]]);
		}
		printf("\n");
	}
	return 0;
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:52: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:55:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &mmap[i][j]);
                             ^
# Verdict Execution time Memory Grader output
1 Correct 489 ms 63100 KB Output is correct
2 Correct 369 ms 165112 KB Output is correct
3 Partially correct 396 ms 54204 KB Output is partially correct
4 Correct 436 ms 57636 KB Output is correct
5 Correct 483 ms 57616 KB Output is correct
6 Correct 353 ms 57876 KB Output is correct
7 Partially correct 479 ms 53764 KB Output is partially correct
8 Partially correct 263 ms 51292 KB Output is partially correct
9 Partially correct 499 ms 53764 KB Output is partially correct
10 Partially correct 236 ms 51284 KB Output is partially correct
11 Correct 499 ms 56860 KB Output is correct
12 Execution timed out 500 ms 56856 KB Execution timed out
13 Halted 0 ms 0 KB -