답안 #22680

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22680 2017-04-30T06:28:38 Z 이대회 트래쉬 대회에야옹(#967, dofwk1526, HUIDONG, mincl) Young Zebra (KRIII5_YZ) C++14
0 / 7
26 ms 10164 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 == 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);

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

	

	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 19 ms 6456 KB Output is partially correct
2 Partially correct 26 ms 7300 KB Output is partially correct
3 Partially correct 16 ms 7132 KB Output is partially correct
4 Partially correct 13 ms 4612 KB Output is partially correct
5 Partially correct 16 ms 3864 KB Output is partially correct
6 Partially correct 16 ms 3692 KB Output is partially correct
7 Partially correct 13 ms 7428 KB Output is partially correct
8 Partially correct 16 ms 6760 KB Output is partially correct
9 Partially correct 19 ms 7432 KB Output is partially correct
10 Partially correct 26 ms 6764 KB Output is partially correct
11 Partially correct 16 ms 7740 KB Output is partially correct
12 Partially correct 16 ms 10164 KB Output is partially correct
13 Partially correct 19 ms 6492 KB Output is partially correct
14 Incorrect 19 ms 5912 KB Output isn't correct
15 Halted 0 ms 0 KB -