Kansas
Time limit2sMemory limit1024 MB
Track the clock-bearing driving segments and rest breaks to count breaks before the path first crosses the start, or report -1.
- Level
Medium5 of 10
- Topics
- Geometry, Simulation, Math
- Solved
- No attempts yet
Problem
The road map of Kansas is a grid. Straight roads run north to south and straight roads run east to west, each spaced 1 mile apart. A truck driver receives instructions in this form: drive north for two hours at 45 miles per hour, then west for five hours at 65 miles per hour.
The driver has to take a 1 hour break after every 5 hours of continuous driving. Those 5 hours carry over from one instruction to the next, because changing direction is not a rest. The driver does not move during a break.
Count how many breaks the driver has taken at the moment she first passes through or returns to the point she started from. If she reaches that point at the exact instant a break would begin, she reaches it first, so that break is not counted. The moment of departure itself does not count as passing through.
Input
The first line contains the number of instructions (). Each of the next lines holds one instruction: the direction , the number of hours (), and the speed () in miles per hour, in that order. and are integers.
The direction is written as the position of the hour hand on an analog clock. 12 is north, 6 is south, 9 is west, 3 is east.
Output
Print one integer, the number of breaks the driver took before she first passed through or returned to the starting point. If she never reaches it after following every instruction, print -1.