이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const vector<int> dx = {-1, 1, 0, 0},
	  dy = {0, 0, -1, 1};
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int h, w; cin >> h >> w;
	vector<string> grid(h);
	for (string& s : grid) cin >> s;
	deque<pair<int, pair<int, int>>> dq;
	dq.push_front({1, {0, 0}});
	vector<vector<bool>> vis(h, vector<bool>(w));
	int ans = 1;
	while (!dq.empty()) {
		int d = dq.front().first;
		pair<int, int> pla = dq.front().second;
		dq.pop_front();
		if (vis[pla.first][pla.second]) continue;
		vis[pla.first][pla.second] = true;
		ans = max(ans, d);
		for (int i = 0; i < 4; ++i) {
			pair<int, int> ne = {pla.first + dx[i], pla.second + dy[i]};
			if (ne.first < 0 || ne.first >= h || ne.second < 0 || ne.second >= w || grid[ne.first][ne.second] == '.') continue;
			if (grid[pla.first][pla.second] == grid[ne.first][ne.second]) {
				dq.push_front({d, ne});
			} else {
				dq.push_back({d + 1, ne});
			}
		}
	}
	cout << ans << '\n';
	return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |