Submission #523345

# Submission time Handle Problem Language Result Execution time Memory
523345 2022-02-07T13:59:23 Z blue Zoo (COCI19_zoo) C++17
110 / 110
120 ms 6104 KB
#include <iostream>
#include <string>
#include <deque>
#include <vector>
using namespace std;

using vi = vector<int>;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int R, C;
	cin >> R >> C;

	char S[R*C];
	for(int i = 0; i < R*C; i++) cin >> S[i];

	int res = 1;

	vi dist(R*C, R*C*5);
	dist[0] = 0;

	deque<int> tbv;

	tbv.push_back(0);

	while(!tbv.empty())
	{
		int u = tbv.front();
		tbv.pop_front();

		res = max(res, dist[u] + 1);

		vi edge;
		if(u % C != 0) edge.push_back(u-1);
		if(u % C != C-1) edge.push_back(u+1);
		if(u / C != 0) edge.push_back(u-C);
		if(u / C != R-1) edge.push_back(u+C);

		for(int v : edge)
		{
			int d = (S[u] != S[v]);

			if(S[v] == '*') continue;

			if(dist[v] <= dist[u] + d) continue;

			dist[v] = dist[u] + d;

			if(d == 0) tbv.push_front(v);
			else tbv.push_back(v);
		}
	}

	cout << res << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 22 ms 5884 KB Output is correct
17 Correct 24 ms 5832 KB Output is correct
18 Correct 28 ms 6104 KB Output is correct
19 Correct 27 ms 5960 KB Output is correct
20 Correct 24 ms 5824 KB Output is correct
21 Correct 87 ms 5680 KB Output is correct
22 Correct 84 ms 5660 KB Output is correct
23 Correct 120 ms 5708 KB Output is correct
24 Correct 87 ms 5968 KB Output is correct
25 Correct 84 ms 5876 KB Output is correct
26 Correct 84 ms 5828 KB Output is correct
27 Correct 92 ms 5676 KB Output is correct
28 Correct 89 ms 5700 KB Output is correct
29 Correct 84 ms 5984 KB Output is correct
30 Correct 83 ms 5828 KB Output is correct