#P10096. Robot Cleaning Coverage

    ID: 12080 Type: Default 1000ms 256MiB

Robot Cleaning Coverage

Robot Cleaning Coverage

Given a sequence of $n$ move operations, where the $i$-th operation is defined by a direction $d_i$ and a distance $a_i$, compute the total area cleaned by the robot. The robot starts at the origin $(0,0)$. The direction $d_i$ can be one of the following characters:

  • N: Move north (increases the $y$ coordinate by 1 per step).
  • E: Move east (increases the $x$ coordinate by 1 per step).
  • S: Move south (decreases the $y$ coordinate by 1 per step).
  • W: Move west (decreases the $x$ coordinate by 1 per step).

For each move operation, the robot travels one unit at a time in the specified direction for $a_i$ steps, cleaning every point it passes through (including the starting point of that move). You are required to determine the total number of unique grid points that the robot has visited (cleaned) after performing all operations.

Formally, if the sequence of operations is given by $$\{(d_1,a_1), (d_2,a_2), \ldots, (d_n,a_n)\},$$ and the robot starts at $(0,0)$, then every intermediate point reached during the moves is considered cleaned. Output the count of distinct points cleaned.

inputFormat

The first line contains an integer $n$, denoting the number of move operations.
Each of the next $n$ lines contains a character $d_i$ (one of 'N', 'E', 'W', 'S') and an integer $a_i$, separated by a space, representing the direction and the distance of the move, respectively.

outputFormat

Output a single integer representing the total number of distinct grid points visited by the robot.

sample

4
N 1
E 1
S 1
W 1
4