Submission #1109362

#TimeUsernameProblemLanguageResultExecution timeMemory
1109362classicTracks in the Snow (BOI13_tracks)C++17
2.19 / 100
478 ms95412 KiB
#include <bits/stdc++.h>

const std::vector<int> directionX{-1, 1, 0, 0};
const std::vector<int> directionY{0, 0, -1, 1};

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int numRow, numColumn;
	std::cin >> numRow >> numColumn;
	std::vector<std::string> snow(numRow);
	for (int row = 0; row < numRow; row++) {
		std::cin >> snow[row];
	}
	std::queue<std::pair<int, int>> queue;
	std::vector<std::vector<int>> depth(numRow, std::vector<int>(numColumn));
	queue.emplace(0, 0);
	depth[0][0] = 1;
	int result = 1;
	while (!queue.empty()) {
		auto [currentRow, currentColumn] = queue.front();
		queue.pop();
		result = std::max(result, depth[currentRow][currentColumn]);
		for (int direction = 0; direction < 4; direction++) {
			int nextRow = currentRow + directionX[direction];
			int nextColumn = currentColumn + directionY[direction];
			if (nextRow >= 0 && nextRow < numRow && nextColumn >= 0 && nextColumn < numColumn && depth[nextRow][nextColumn] == 0) {
				if (snow[currentRow][currentColumn] == snow[nextRow][nextColumn]) {
					depth[nextRow][nextColumn] = depth[currentRow][currentColumn];
					queue.emplace(nextRow, nextColumn);
				} else {
					depth[nextRow][nextColumn] = depth[currentRow][nextColumn] + 1;
					queue.emplace(nextRow, nextColumn);
				}
			}
		}
	}
	std::cout << result;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...