← 返回 microsoft 的题目列表Robot Vacuum Cleaner Movement
类型:online_judge
microsoft
Problem Description
Given a m x n 2D grid representing the room where:
0 represents an empty space (areas the robot can move).
1 represents an obstacle (areas the robot cannot penetrate).
The robot is located at the starting position (0, 0). The robot moves with the following rules:
Start at the initial position (0, 0) and move to the right.
Whenever an obstacle is encountered, the robot turns 90 degrees clockwise.
If the robot cannot advance, it stops.
Calculate the total number of positions the robot cleaned before stopping.
The input guarantees that (0, 0) is 0 and the robot can start and reach at least one empty space.
Input Format
The first line contains two integers m and n, the number of rows and columns in the room.
The next m lines each contain n integers, representing the room grid.
Output Format
Output a single integer, the total number of positions cleaned by the robot before stopping.
Example
Input:
3 3
0 0 0
1 1 0
0 0 0
Output:
6
Constraints
1 <= m, n <= 100
Example
Input
3 3
0 0 0
1 1 0
0 0 0