Robot
Time limit6sMemory limit1024 MB
Count how many times a robot that repeats a list of move lengths, turning right after each move, is at a given point before its battery runs out.
- Level
Medium7 of 10
- Topics
- Math, Prefix sum, Simulation, Implementation
- Solved
- No attempts yet
Problem
The robot starts at on a coordinate plane and faces north (the direction of increasing ). You program it with a sequence of commands . When the robot is switched on, it performs moves in order. Move (for ) drives forward units, then turns 90 degrees to the right.
The battery lasts for seconds. Driving one unit takes 1 second, and each 90 degree turn takes 1 second.
Given a point , count how many times the robot is at that point before the battery runs out.
Input
The first line contains two integers and (, ), the length of the robot's program and the battery time in seconds. The second line contains integers (), the commands in order. The third line contains two integers and (), the point being queried.
Output
Print one integer: the number of moments at which the robot is at the point . A moment at time 0 or at time counts too.
Hint
In the sample, the robot is at the point at 6 and 22 seconds after it is switched on. The figure below shows the robot's route.
