이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>
using namespace std;
struct node
{
	int x, y;
	int layer;
	const bool operator< (const node other) const
	{
		return layer > other.layer;
	}
};
int r, c;
bool outofbounds(node n)
{
	return !(0 <= n.x && n.x < r && 0 <= n.y && n.y < c);
}
int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);
	int i, j, deepest_layer = 0;
	cin >> r >> c;
	vector<string> g(r);
	for (i = 0; i < r; i++)
	{
		cin >> g[i];
	}
	priority_queue<node> q;
	q.push({ 0, 0, 0 });
	vector<vector<bool>> been(r, vector<bool>(c, 0));
	vector<pair<int, int>> directions = { {0, 1}, {0, -1}, {1, 0}, {-1, 0} };
	while (!q.empty())
	{
		node current = q.top();
		q.pop();
		for (pair<int, int>& d : directions)
		{
			node neighbour;
			neighbour.x = current.x + d.first;
			neighbour.y = current.y + d.second;
			if (!outofbounds(neighbour) && !been[neighbour.x][neighbour.y] && g[neighbour.x][neighbour.y] != '*')
			{
				neighbour.layer = current.layer + (g[neighbour.x][neighbour.y] != g[current.x][current.y]);
				deepest_layer = max(deepest_layer, neighbour.layer);
				q.push(neighbour);
				been[neighbour.x][neighbour.y] = true;
			}
		}
	}
	cout << deepest_layer + 1;
}
컴파일 시 표준 에러 (stderr) 메시지
zoo.cpp: In function 'int main()':
zoo.cpp:36:9: warning: unused variable 'j' [-Wunused-variable]
   36 |  int i, j, deepest_layer = 0;
      |         ^| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |