Submission #22847

# Submission time Handle Problem Language Result Execution time Memory
22847 2017-04-30T07:51:17 Z dried chocochip on Daegu asphalt(#897, suzy, zych1751, Acka) Young Zebra (KRIII5_YZ) C++11
2 / 7
113 ms 22936 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(!(ni >= 0 && ni < n && nj >= 0 && nj < m))
			if(mm.count({nii,njj}) != 0)
				cc_inf[c_idx] = true;

		if(!visited[nii][njj] && mmap[ii][jj] == mmap[nii][njj])
			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 < n; i++)
		for(int j = 0; j < m; j++)
			if(!visited[i][j])
			{
				si = i, sj = j;
				c_idx++;

				mm.clear();
				dfs(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:50: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:53: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 29 ms 11484 KB Output is correct
2 Correct 43 ms 10380 KB Output is correct
3 Correct 36 ms 10296 KB Output is correct
4 Partially correct 39 ms 7180 KB Output is partially correct
5 Partially correct 46 ms 6024 KB Output is partially correct
6 Correct 59 ms 5572 KB Output is correct
7 Correct 49 ms 9444 KB Output is correct
8 Partially correct 39 ms 6280 KB Output is partially correct
9 Correct 49 ms 9444 KB Output is correct
10 Correct 43 ms 6272 KB Output is correct
11 Correct 63 ms 15664 KB Output is correct
12 Correct 113 ms 22936 KB Output is correct
13 Partially correct 66 ms 9348 KB Output is partially correct
14 Partially correct 43 ms 8308 KB Output is partially correct
15 Correct 46 ms 5524 KB Output is correct
16 Partially correct 33 ms 7740 KB Output is partially correct
17 Correct 59 ms 11196 KB Output is correct
18 Correct 49 ms 11060 KB Output is correct
19 Correct 56 ms 3740 KB Output is correct
20 Correct 46 ms 6652 KB Output is correct
21 Correct 63 ms 10196 KB Output is correct
22 Correct 43 ms 10048 KB Output is correct
23 Correct 39 ms 5228 KB Output is correct
24 Correct 46 ms 5352 KB Output is correct
25 Correct 56 ms 7088 KB Output is correct
26 Correct 0 ms 3740 KB Output is correct
27 Correct 0 ms 3740 KB Output is correct
28 Correct 0 ms 3792 KB Output is correct
29 Correct 0 ms 3792 KB Output is correct
30 Correct 0 ms 3740 KB Output is correct
31 Correct 0 ms 3740 KB Output is correct
32 Correct 0 ms 3740 KB Output is correct
33 Correct 0 ms 3740 KB Output is correct
34 Correct 0 ms 3740 KB Output is correct
35 Correct 0 ms 3740 KB Output is correct
36 Correct 0 ms 4056 KB Output is correct
37 Correct 3 ms 3892 KB Output is correct
38 Correct 3 ms 3740 KB Output is correct
39 Correct 3 ms 3904 KB Output is correct
40 Correct 0 ms 4072 KB Output is correct