답안 #22857

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22857 2017-04-30T07:52:40 Z dried chocochip on Daegu asphalt(#897, suzy, zych1751, Acka) Young Zebra (KRIII5_YZ) C++11
2 / 7
113 ms 22940 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);
	}

	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;
	}
}

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:56: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:59:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &mmap[i][j]);
                             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 11492 KB Output is correct
2 Correct 53 ms 10380 KB Output is correct
3 Correct 46 ms 10296 KB Output is correct
4 Partially correct 49 ms 7172 KB Output is partially correct
5 Partially correct 59 ms 6024 KB Output is partially correct
6 Correct 59 ms 5572 KB Output is correct
7 Correct 46 ms 9440 KB Output is correct
8 Partially correct 49 ms 6280 KB Output is partially correct
9 Correct 46 ms 9440 KB Output is correct
10 Correct 49 ms 6268 KB Output is correct
11 Correct 73 ms 15660 KB Output is correct
12 Correct 113 ms 22940 KB Output is correct
13 Partially correct 66 ms 9348 KB Output is partially correct
14 Partially correct 46 ms 8312 KB Output is partially correct
15 Correct 53 ms 5528 KB Output is correct
16 Partially correct 46 ms 7740 KB Output is partially correct
17 Correct 66 ms 11192 KB Output is correct
18 Correct 53 ms 11064 KB Output is correct
19 Correct 63 ms 3740 KB Output is correct
20 Correct 43 ms 6652 KB Output is correct
21 Correct 63 ms 10200 KB Output is correct
22 Correct 46 ms 10052 KB Output is correct
23 Correct 39 ms 5224 KB Output is correct
24 Correct 49 ms 5352 KB Output is correct
25 Correct 56 ms 7084 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 3788 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 3 ms 4048 KB Output is correct
37 Correct 3 ms 3892 KB Output is correct
38 Correct 3 ms 3740 KB Output is correct
39 Correct 0 ms 3904 KB Output is correct
40 Correct 3 ms 4072 KB Output is correct