cswork / OAOpen practice workspace

WeRideOA #3

Bob Navigates a Maze (BFS, Collect All Gold)

Estimated HardStatement and editorial — judging is being prepared

Topics (AI-labelled)Shortest PathsTree & Game DPGrid Search

Bob and Alice have teamed up on a game where, after winning the first round, they now have access to a maze with hidden gold. If Bob can collect all the gold coins and deliver them to Alice, they can split the gold. Bob can move horizontally or vertically as long as he stays in the maze, and the cell is not blocked.

The maze is represented by an n × m array. Each cell has a value, where 0 is open, 1 is blocked, and 2 is open and contains a gold coin. Bob starts at the top left position (0, 0), and Alice's position is given by (x, y). Determine the shortest path Bob can take to collect all gold coins and deliver them to Alice. If Bob can't collect and give all the gold coins, return -1.

Editorial

Loading solution…