답안 #22690

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22690 2017-04-30T06:35:10 Z 이대회 트래쉬 대회에야옹(#967, dofwk1526, HUIDONG, mincl) Young Zebra (KRIII5_YZ) C++14
0 / 7
29 ms 10496 KB
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <map>
#include <set>
#include <string>

using namespace std;

int N, M;
char sp[444][444];
int bcnt, wcnt;
bool visit[444][444];
int ans[444][444];
int cnt;
int mxcnt;
char cur;
int spx, spy;
int an[444];
int idx = 1;

void dfs(int, int);

int main()
{
	cin >> N >> M;
	for (int i = 0; i < N; i++)
		scanf("%s", sp[i]);

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			cnt = 0;
			mxcnt = 0;
			cur = sp[i][j];

			if(!ans[i][j])
			{
				dfs(i, j);
				an[idx++] = cnt;
			}
		}
	}

	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			printf("%d ", an[ans[i][j]]);
		}
		printf("\n");
	}
}

void dfs(int x, int y)
{
	cnt++;
	visit[x][y] = true;

	if (x - 1 >= 0 && !visit[x - 1][y] && sp[x - 1][y] == cur)
	{
		dfs(x - 1, y);
	}
	if (x + 1 < N && !visit[x + 1][y] && sp[x + 1][y] == cur)
	{
		dfs(x + 1, y);
	}
	if (y - 1 >= 0 && !visit[x][y - 1] && sp[x][y - 1] == cur)
	{
		dfs(x, y - 1);
	}
	if (y + 1 < M && !visit[x][y + 1] && sp[x][y + 1] == cur)
	{
		dfs(x, y + 1);
	}

	if (x == 0 && !visit[N - 1][y] && sp[N - 1][y] == cur)
		dfs(N - 1, y);
	if (x == N - 1 && !visit[0][y] && sp[0][y] == cur)
		dfs(0, y);
	if (y == 0 && !visit[x][M - 1] && sp[x][M - 1] == cur)
		dfs(x, M - 1);
	if (y == M - 1 && !visit[x][0] && sp[x][0] == cur)
		dfs(x, 0);

	ans[x][y] = idx;
}

Compilation message

YZ.cpp: In function 'int main()':
YZ.cpp:34:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", sp[i]);
                     ^
# 결과 실행 시간 메모리 Grader output
1 Partially correct 16 ms 6376 KB Output is partially correct
2 Partially correct 19 ms 6868 KB Output is partially correct
3 Partially correct 23 ms 7284 KB Output is partially correct
4 Partially correct 16 ms 4664 KB Output is partially correct
5 Partially correct 16 ms 3864 KB Output is partially correct
6 Partially correct 19 ms 3720 KB Output is partially correct
7 Partially correct 19 ms 7216 KB Output is partially correct
8 Partially correct 16 ms 8116 KB Output is partially correct
9 Partially correct 23 ms 6836 KB Output is partially correct
10 Partially correct 16 ms 6760 KB Output is partially correct
11 Partially correct 23 ms 10496 KB Output is partially correct
12 Partially correct 23 ms 10496 KB Output is partially correct
13 Partially correct 29 ms 6012 KB Output is partially correct
14 Incorrect 23 ms 5912 KB Output isn't correct
15 Halted 0 ms 0 KB -