Internet for a rainy day
Time limit1sMemory limit1024 MB
Given N crew paths on a checkerboard grid, find the coordinates of the K-th black block to get connected when a path passes alongside it.
- Level
Medium7 of 10
- Topics
- Binary search, Geometry, Implementation
- Solved
- No attempts yet
Statement
The city of Shakhmatovsk has two internet providers that are carrying out a nationwide internet rollout plan. The city lies on an infinite integer grid. Straight streets run along every grid line, and each unit square is a block. A block is identified by the coordinates of its lower left corner. The blocks are colored black and white in a checkerboard pattern, and the block at is black.
The provider "Black Internet" connects the black blocks. Residents of the block that is connected K-th will receive a 10% discount. The rollout takes N days. On day , a crew starts at and moves along one of the city streets. The crew passes blocks in the given direction. While moving, it connects every black block that is not yet connected and shares a side with the crew's path (see the figure). Write a program that finds the coordinates of the block that is connected K-th. It is guaranteed that at least K blocks are connected during the rollout.
Input
The first line contains two integers N and K: , . Each of the next N lines describes the crew's path on one day. The line contains and , the starting point of the path, the character , the direction of movement, and , the distance the crew travels. It is given that , , and . The character is one of 'N' (north, y increases), 'E' (east, x increases), 'S' (south, y decreases), or 'W' (west, x decreases).
Output
Print the x and y coordinates of the block that is connected K-th.