제출 #1296294

#제출 시각아이디문제언어결과실행 시간메모리
1296294__ugur__Tracks in the Snow (BOI13_tracks)C++17
0 / 100
592 ms122708 KiB
#include <bits/stdc++.h>

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	
	int h,w;
	cin >> h >> w;
	vector<vector<int>> depths(h, vector<int>(w, -1));
	vector<string> meadow(h);
	for(auto& str : meadow)
		cin >> str;

	deque<pair<int, int>> qu;
	
	int ans = 0;

	const int xoff[4] = {-1, 0, 0, 1};
	const int yoff[4] = {0, -1, 1, 0};

	depths[0][0] = 0;
	qu.push_back({0, 0});

	while(qu.size()) {
		auto [y, x] = qu.front();
		qu.pop_front();
		ans = max(ans, depths[y][x]);
		for(int cy,cx,i=0; i<4; i++) {
			cy = y + yoff[i];
			cx = x + xoff[i];
			if(cy < 0 || cx < 0 || cy >= h || cx >= w || depths[cy][cx] >= 0)
				continue;
			if(meadow[y][x] == meadow[cy][cx]) {
				qu.push_front({cy, cx});
				depths[cy][cx] = depths[y][x];
			}
			else {
				qu.push_back({cy, cx});
				depths[cy][cx] = depths[y][x]+1;
			}
		}
	}

	cout << ans << '\n';

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...