CT29079

The Flooded Yard of Pearldeep

MediumL4 · Loop LordAcceptance: 0.0%XP: 35

Steward the assayer watches over the coral atoll of Pearldeep's stores of halls. A careful computation stands between order and chaos. Task: '.' is open and '#' is blocked. Print the fewest moves (4-directional) from the top-left to bottom-right cell, or -1 if unreachable. Input format: First line: r and c. Next r lines: rows of '.' and '#'. Output format: Print the shortest distance or -1. Constraints: 1 <= r,c <= 160; r*c <= 10^6; endpoints are '.'.

Example 1:

Input: 141 59 ..#..#.#............#.....##..#.......##...##..#..#........ ...#...#.#..#........#..#...##.#..#.#.#......#...##...#...# ###.#..............#.#........#.#............#............# #...#..#.......#...#....#......#...........#..........#..#. ..##..#..#..............#........###..#....#......#####.... ..#..##....##.#..#.....#....#................#..#..#.#...#. ........#...#....#...###.......#......#..........#...#..#.. .##.....###..#....###.................#.#.#........##..###. .....#..###..#..#.#....#...#..#.#....#.......#..#..#....... .#....######.##.#.#...#..#.........#...#...............#... .#.###....#........#..##.....#........#..#....#.##.......#. ..............#.#...........##.#..####......#.#.#...####.#. ..##.#...............#...........#.##..#......#............ ..#..........…
Output: -1

Example 2:

Input: 112 100 .......#.....#........#.#......#.......##............#...........#...#.....#....###..........#.##..# #......###...####......#....###......#......#..#......#....##......#..##......#....#.##.#..........# .....##......##....#........#...#..#.##....#.....#..#.....#...##...#........#....#####.#.#..#..#.##. ..##..........#.....#.#.....#.#.#.#.#.#....##.........#.......#.....#...#..##.##...#....#...##..#... ....#......#..##..#.#..##..##.##..#....#.......#.##...##.###.#.#.#....#..#..........#.####..#...##.. .......#....#.#..........###.##...........#...#.....#.#....#..#........###.......................... #....#.##.#....#.#.............#..###...#....#.##.....#.#...##....#..#....#.......#.#.....#...##.... .......#..............###.....#.............#....#..#...##.....#...##.....##.......#.…
Output: 210

Example 3:

Input: 18 9 .#......# .#...#.#. .......## .....#... ......... ....#.... .#..#...# .......#. .#.#.##.# ....#.#.. ....#..#. ...#.#..# .......## #.##..#.. ....#...# ....#.... ..#...##. ..#.#....
Output: 25

Constraints:

1 <= r,c <= 160; r*c <= 10^6; endpoints are '.'.

Loading...
Test Cases:No test cases
No test cases available.
The Flooded Yard of Pearldeep - MEDIUM Coding Problem | CodeTikki