Drone Control
InterviewTime limit1sMemory limit1024 MB
Given obstacle cells and a string of U, D, R, L moves, find the drone's final position when it stays put whenever the next cell holds an obstacle.
- Level
Easy2 of 10
- Topics
- Simulation, Hash map
- Solved
- No attempts yet
Problem
A drone starts at the origin of the coordinate plane. You can enter four kinds of commands.
U: increases the coordinate of the drone by .D: decreases the coordinate of the drone by .R: increases the coordinate of the drone by .L: decreases the coordinate of the drone by .
There are also obstacles on the plane. If the cell that the drone tries to move into contains an obstacle, the drone does not move and stays where it is. Given the obstacle positions and the entered commands, find the final position of the drone.
Input
The first line contains two integers and , the number of obstacles and the number of commands, separated by a space. ()
The next lines each contain two integers and , the coordinates of the -th obstacle, separated by a space. All obstacle positions are distinct, and there is no obstacle at the origin. ()
The -th line is a string of the entered commands. Each character of the string is one of U, D, R, or L.
Output
After all commands are entered, print the coordinate and the coordinate of the drone's position, separated by a space.