Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <fstream>
- int m = 0;
- int r = 0;
- bool tryMoveRight(std::vector<std::vector<int>>& map, int x, int y, int color) {
- for (int i = 0; i < r; ++i) {
- if (map[y - i][x] == -1) {
- return false;
- }
- }
- for (int i = 0; i < r; ++i) {
- map[y - i][x] = color;
- }
- return true;
- }
- bool tryMoveDown(std::vector<std::vector<int>>& map, int x, int y, int color) {
- for (int i = 0; i < r; ++i) {
- if (map[y][x - i] == -1) {
- return false;
- }
- }
- for (int i = 0; i < r; ++i) {
- map[y][x - i] = color;
- }
- return true;
- }
- void findPath(std::vector<std::vector<int>>& map, int x, int y, int color) {
- if (tryMoveRight(map, x + 1, y, color + 1)) {
- findPath(map, x + 1, y, color + 1);
- }
- if (tryMoveDown(map, x, y + 1, color + 1)) {
- findPath(map, x, y + 1, color + 1);
- }
- }
- int main() {
- std::ifstream input("input.txt");
- if (!input.good()) {
- std::cout << "File error: input.txt\n";
- return 1;
- }
- input >> m >> r;
- std::vector<std::vector<int>> map(m + 2);
- for (int i = 0; i < m + 2; ++i) {
- map[i].resize(m + 2);
- }
- for (int i = 0; i < m + 2; ++i) {
- map[0][i] = -1;
- map[i][0] = -1;
- map[m + 1][i] = -1;
- map[i][m + 1] = -1;
- }
- for (int i = 1; i < m + 1; ++i) {
- char c = 0;
- for (int j = 1; j < m + 1; ++j) {
- input >> c;
- map[i][j] = c == '.' ? 0 : -1;
- }
- }
- input.close();
- findPath(map, r, r, 0);
- std::ofstream output("output.txt");
- if (!output.good()) {
- std::cout << "File error: output.txt\n";
- return 1;
- }
- if (map[m][m] == 0) {
- output << "No";
- } else {
- output << map[m][m];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement