Submission #22734

# Submission time Handle Problem Language Result Execution time Memory
22734 2017-04-30T07:06:24 Z dried chocochip on Daegu asphalt(#897, suzy, zych1751, Acka) Young Zebra (KRIII5_YZ) C++11
2 / 7
46 ms 11072 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)
{
	return (val+m*m*m)%m;
}

int si, sj;
bool cc_inf[400*400+2];

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]++;

	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(!(si == ni && sj == nj) && (si == nii && sj == njj))
			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++;
				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:43: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:46: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 33 ms 9316 KB Output is correct
2 Correct 29 ms 8488 KB Output is correct
3 Correct 43 ms 8420 KB Output is correct
4 Partially correct 33 ms 5884 KB Output is partially correct
5 Partially correct 26 ms 4628 KB Output is partially correct
6 Correct 33 ms 4288 KB Output is correct
7 Correct 33 ms 7980 KB Output is correct
8 Partially correct 33 ms 5516 KB Output is partially correct
9 Correct 39 ms 7980 KB Output is correct
10 Correct 26 ms 5504 KB Output is correct
11 Correct 46 ms 11064 KB Output is correct
12 Correct 33 ms 11072 KB Output is correct
13 Partially correct 39 ms 7812 KB Output is partially correct
14 Partially correct 43 ms 7032 KB Output is partially correct
15 Correct 29 ms 5040 KB Output is correct
16 Partially correct 33 ms 6608 KB Output is partially correct
17 Partially correct 29 ms 7316 KB Output is partially correct
18 Correct 43 ms 7312 KB Output is correct
19 Correct 36 ms 3736 KB Output is correct
20 Correct 33 ms 5892 KB Output is correct
21 Correct 33 ms 8544 KB Output is correct
22 Correct 33 ms 8436 KB Output is correct
23 Correct 33 ms 4820 KB Output is correct
24 Correct 29 ms 4912 KB Output is correct
25 Correct 29 ms 6116 KB Output is correct
26 Correct 0 ms 3736 KB Output is correct
27 Correct 0 ms 3736 KB Output is correct
28 Correct 0 ms 3744 KB Output is correct
29 Correct 0 ms 3740 KB Output is correct
30 Correct 0 ms 3736 KB Output is correct
31 Correct 0 ms 3736 KB Output is correct
32 Partially correct 0 ms 3736 KB Output is partially correct
33 Partially correct 0 ms 3736 KB Output is partially correct
34 Correct 0 ms 3736 KB Output is correct
35 Correct 0 ms 3736 KB Output is correct
36 Correct 0 ms 3944 KB Output is correct
37 Correct 0 ms 3816 KB Output is correct
38 Correct 0 ms 3736 KB Output is correct
39 Correct 0 ms 3828 KB Output is correct
40 Correct 0 ms 3952 KB Output is correct