This page is still under construction.

Parts of this page are still being built. What you see may change.

Robot

Time limit1sMemory limit512 MB

Summary
Find a sequence of at most 700 moves that drives a robot on a walled grid to (0,0) from either of two unknown starting cells.
Level

Medium6 of 10

Topics
BFS, Graph, Simulation, Implementation
Solved
No attempts yet

Problem

A robot is placed on a field modeled as an n×mn \times m grid. Some of the grid cells are walls.

The robot accepts four types of instructions: up, down, left, right.

Suppose the robot is currently at the coordinate (x,y)(x, y). Then the effect of executing each instruction is as follows.

  • up: If x=0x = 0 or (x−1,y)(x - 1, y) is a wall, the robot does not move. Otherwise, the robot moves to (x−1,y)(x - 1, y).
  • down: If x=n−1x = n - 1 or (x+1,y)(x + 1, y) is a wall, the robot does not move. Otherwise, the robot moves to (x+1,y)(x + 1, y).
  • left: If y=0y = 0 or (x,y−1)(x, y - 1) is a wall, the robot does not move. Otherwise, the robot moves to (x,y−1)(x, y - 1).
  • right: If y=m−1y = m - 1 or (x,y+1)(x, y + 1) is a wall, the robot does not move. Otherwise, the robot moves to (x,y+1)(x, y + 1).

You know that the starting position of the robot is either (a,b)(a, b) or (c,d)(c, d). Find a sequence of at most qq instructions such that the robot always ends up at (0,0)(0, 0) whether it starts from (a,b)(a, b) or from (c,d)(c, d). It can be proven that a solution exists for every input satisfying the problem constraints.

Constraints

  • 1≤n≤101 \le n \le 10
  • 1≤m≤101 \le m \le 10
  • 0≤a≤n−10 \le a \le n - 1
  • 0≤b≤m−10 \le b \le m - 1
  • 0≤c≤n−10 \le c \le n - 1
  • 0≤d≤m−10 \le d \le m - 1
  • g[0][0]=g[a][b]=g[c][d]=0g[0][0] = g[a][b] = g[c][d] = 0
  • There exists a finite sequence of instructions to move the robot from (a,b)(a, b) to (0,0)(0, 0)
  • There exists a finite sequence of instructions to move the robot from (c,d)(c, d) to (0,0)(0, 0)
  • q=700q = 700

Examples1

  1. Example 1

    Input
    1 1
    0
    0 0 0 0
    
    Expected output
    0