Submission #205409

# Submission time Handle Problem Language Result Execution time Memory
205409 2020-02-28T20:29:07 Z luciocf Zoo (COCI19_zoo) C++14
110 / 110
114 ms 3328 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

const int maxn = 1e3+10;

int n, m;
char tab[maxn][maxn];

bool mark[maxn][maxn];

int linha[] = {-1, 1, 0, 0};
int coluna[] = {0, 0, -1, 1};

int bfs(void)
{
	deque<pii> fila;

	fila.push_front({1, 1});
	mark[1][1] = 1;

	int ans = 1;
	char ant = tab[1][1];

	while (!fila.empty())
	{
		int x = fila.front().first, y = fila.front().second;
		fila.pop_front();

		if (tab[x][y] != ant) ans++;
		ant = tab[x][y];

		for (int i = 0; i < 4; i++)
		{
			int a = x+linha[i], b = y+coluna[i];

			if (a < 1 || a > n || b < 1 || b > m || tab[a][b] == '*' || mark[a][b]) continue;

			if (tab[a][b] == tab[x][y]) fila.push_front({a, b});
			else fila.push_back({a, b});


			mark[a][b] = 1;
		}
	}

	return ans;
}

int main(void)
{
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			scanf(" %c", &tab[i][j]);

	printf("%d\n", bfs());
}

Compilation message

zoo.cpp: In function 'int main()':
zoo.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
zoo.cpp:58:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %c", &tab[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 7 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 380 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 7 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 73 ms 3328 KB Output is correct
17 Correct 70 ms 3320 KB Output is correct
18 Correct 73 ms 3320 KB Output is correct
19 Correct 73 ms 3320 KB Output is correct
20 Correct 70 ms 3192 KB Output is correct
21 Correct 99 ms 3196 KB Output is correct
22 Correct 96 ms 3192 KB Output is correct
23 Correct 97 ms 3232 KB Output is correct
24 Correct 106 ms 3320 KB Output is correct
25 Correct 99 ms 3192 KB Output is correct
26 Correct 99 ms 3192 KB Output is correct
27 Correct 99 ms 3192 KB Output is correct
28 Correct 98 ms 3196 KB Output is correct
29 Correct 102 ms 3320 KB Output is correct
30 Correct 114 ms 3320 KB Output is correct