Submission #22868

# Submission time Handle Problem Language Result Execution time Memory
22868 2017-04-30T07:55:25 Z dried chocochip on Daegu asphalt(#897, suzy, zych1751, Acka) Young Zebra (KRIII5_YZ) C++11
2 / 7
119 ms 23092 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};

int mod(int val, int m)
{
	while(val < 0)
		val += m*m*m;
	return val%m;
}

int si, sj;
bool cc_inf[400*400+2];
map<pair<int,int>, int> mm;

void dfs(int i, int j)
{
	int ii = mod(i, n), jj = mod(j, m);
	visited[ii][jj] = true;
	cc[ii][jj] = c_idx;
	cc_sz[c_idx]++;

	if(i >= 0 && i < n && j >= 0 && j < m)
		mm[{i,j}] = 1;

	for(int k = 0; k < 4; k++)
	{
		int ni = i+di[k], nj = j+dj[k];
		int nii = mod(ni, n), njj = mod(nj, m);

		if(!visited[nii][njj] && mmap[ii][jj] == mmap[nii][njj])
			dfs(ni, nj);
	}

}

bool visited2[400][400];

void dfs2(int i, int j)
{
	int ii = mod(i, n), jj = mod(j, m);
	visited2[ii][jj] = true;

	for(int k = 0; k < 4; k++)
	{
		int ni = i+di[k], nj = j+dj[k];
		int nii = mod(ni, n), njj = mod(nj, m);

		if(!(ni >= 0 && ni < n && nj >= 0 && nj < m))
			if(mm.count({nii,njj}) != 0)
				cc_inf[c_idx] = true;
		if(!visited2[nii][njj] && mmap[ii][jj] == mmap[nii][njj])
			dfs2(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 < n; i++)
		for(int j = 0; j < m; j++)
			if(!visited[i][j])
			{
				si = i, sj = j;
				c_idx++;

				mm.clear();
				dfs(i, j);
				dfs2(i, j);
			}

	for(int i = 0; i < n; i++)
	{
		for(int j = 0; j < m; j++)
			printf("%d ", cc_inf[cc[i][j]] ? -1 : cc_sz[cc[i][j]]);
		printf("\n");
	}
	return 0;
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:67: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:70: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 53 ms 11648 KB Output is correct
2 Correct 53 ms 10532 KB Output is correct
3 Correct 53 ms 10448 KB Output is correct
4 Partially correct 63 ms 7332 KB Output is partially correct
5 Partially correct 73 ms 6184 KB Output is partially correct
6 Correct 66 ms 5732 KB Output is correct
7 Correct 49 ms 9600 KB Output is correct
8 Partially correct 49 ms 6436 KB Output is partially correct
9 Correct 56 ms 9596 KB Output is correct
10 Correct 46 ms 6428 KB Output is correct
11 Correct 76 ms 15812 KB Output is correct
12 Correct 119 ms 23092 KB Output is correct
13 Partially correct 83 ms 9504 KB Output is partially correct
14 Partially correct 43 ms 8468 KB Output is partially correct
15 Correct 59 ms 5680 KB Output is correct
16 Partially correct 53 ms 7896 KB Output is partially correct
17 Correct 63 ms 11348 KB Output is correct
18 Correct 59 ms 11220 KB Output is correct
19 Correct 73 ms 3896 KB Output is correct
20 Correct 53 ms 6808 KB Output is correct
21 Correct 66 ms 10352 KB Output is correct
22 Correct 56 ms 10204 KB Output is correct
23 Correct 56 ms 5380 KB Output is correct
24 Correct 49 ms 5512 KB Output is correct
25 Correct 66 ms 7240 KB Output is correct
26 Correct 0 ms 3896 KB Output is correct
27 Correct 0 ms 3896 KB Output is correct
28 Correct 0 ms 3948 KB Output is correct
29 Correct 0 ms 3948 KB Output is correct
30 Correct 0 ms 3896 KB Output is correct
31 Correct 0 ms 3896 KB Output is correct
32 Correct 0 ms 3896 KB Output is correct
33 Correct 0 ms 3896 KB Output is correct
34 Correct 0 ms 3896 KB Output is correct
35 Correct 0 ms 3896 KB Output is correct
36 Correct 3 ms 4204 KB Output is correct
37 Correct 3 ms 4052 KB Output is correct
38 Correct 3 ms 3896 KB Output is correct
39 Correct 3 ms 4060 KB Output is correct
40 Correct 3 ms 4232 KB Output is correct