Submission #1109370

# Submission time Handle Problem Language Result Execution time Memory
1109370 2024-11-06T15:07:40 Z classic Tracks in the Snow (BOI13_tracks) C++17
100 / 100
464 ms 111960 KB
#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::deque<std::pair<int, int>> deque;
	std::vector<std::vector<int>> depth(numRow, std::vector<int>(numColumn));
	deque.emplace_back(0, 0);
	depth[0][0] = 1;
	int result = 1;
	while (!deque.empty()) {
		auto [currentRow, currentColumn] = deque.front();
		deque.pop_front();
		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 && 
				snow[nextRow][nextColumn] != '.' && depth[nextRow][nextColumn] == 0) {
				if (snow[currentRow][currentColumn] == snow[nextRow][nextColumn]) {
					depth[nextRow][nextColumn] = depth[currentRow][currentColumn];
					deque.emplace_front(nextRow, nextColumn);
				} else {
					depth[nextRow][nextColumn] = depth[currentRow][currentColumn] + 1;
					deque.emplace_back(nextRow, nextColumn);
				}
			}
		}
	}
	std::cout << result;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 1616 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 5 ms 1360 KB Output is correct
5 Correct 2 ms 848 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 844 KB Output is correct
12 Correct 4 ms 848 KB Output is correct
13 Correct 2 ms 848 KB Output is correct
14 Correct 2 ms 848 KB Output is correct
15 Correct 7 ms 1616 KB Output is correct
16 Correct 12 ms 1872 KB Output is correct
17 Correct 7 ms 1616 KB Output is correct
18 Correct 5 ms 1616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 848 KB Output is correct
2 Correct 27 ms 8284 KB Output is correct
3 Correct 161 ms 80968 KB Output is correct
4 Correct 51 ms 20552 KB Output is correct
5 Correct 100 ms 45396 KB Output is correct
6 Correct 461 ms 94184 KB Output is correct
7 Correct 2 ms 848 KB Output is correct
8 Correct 2 ms 848 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 2 ms 732 KB Output is correct
12 Correct 2 ms 624 KB Output is correct
13 Correct 30 ms 8300 KB Output is correct
14 Correct 16 ms 4944 KB Output is correct
15 Correct 11 ms 5456 KB Output is correct
16 Correct 15 ms 4176 KB Output is correct
17 Correct 77 ms 20560 KB Output is correct
18 Correct 44 ms 20304 KB Output is correct
19 Correct 52 ms 19024 KB Output is correct
20 Correct 49 ms 17488 KB Output is correct
21 Correct 95 ms 48200 KB Output is correct
22 Correct 103 ms 49736 KB Output is correct
23 Correct 148 ms 39332 KB Output is correct
24 Correct 96 ms 45852 KB Output is correct
25 Correct 210 ms 91920 KB Output is correct
26 Correct 244 ms 111960 KB Output is correct
27 Correct 356 ms 104276 KB Output is correct
28 Correct 425 ms 99024 KB Output is correct
29 Correct 429 ms 99028 KB Output is correct
30 Correct 464 ms 98768 KB Output is correct
31 Correct 383 ms 52272 KB Output is correct
32 Correct 304 ms 103788 KB Output is correct