PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT0000127. Robot (Robot)

    ID: 1634 Loại: Thông thường 1000ms 256MiB Tried: 0 Đã chấp nhận: 0 Độ khó: 5 Đăng bởi: Nhãn>FundamentalsImplementation techniquesComplete SearchState-space searchGraph BasicsCycle detection

Bài tập này chưa được xếp vào lộ trình.

Robot (Robot)

Robot

Source: Bộ Giáo dục và Đào tạo

Version: Phuoc Hung OJ Extended

Problem Statement

Tuan built a robot for a maze-escaping competition. The robot continuously moves straight forward at 11 metre per second. When the cell immediately ahead is blocked, it repeatedly turns 90∘90^\circ to the left until the cell in front is free, then resumes moving. Turns take zero time, and the robot never stops on its own.

The floor is an infinite-looking grid of 1×11\times1 metre cells. Columns increase from left to right and rows from top to bottom; their indices range from −1010-10^{10} to 101010^{10}. The cell at column xx, row yy has coordinates (x,y)(x,y). The maze occupies an N×NN\times N subgrid with top-left cell (1,1)(1,1). Some cells contain obstacles #, while . denotes an empty cell. There are no obstacles outside the maze.

Initially the robot stands at (x,y)(x,y) facing upwards. Its initial cell is unblocked and has at least one adjacent unblocked cell. Both its starting and final cells may lie outside the maze. Determine its coordinates after exactly SS seconds.

Input

  • The first line contains four integers N,x,y,SN,x,y,S.
  • Each of the next NN lines contains exactly NN characters # or ., describing one maze row in top-to-bottom order.

Output

Print two integers, the final xx and yy coordinates after SS seconds, separated by a space.

Subtasks

  • Subtask 1 (50 points): 1≤N≤10001\le N\le1000; −105≤x,y≤105-10^5\le x,y\le10^5; 1≤S≤1051\le S\le10^5; each maze row contains NN characters from #, .; the starting cell and at least one adjacent cell are unblocked.
  • Subtask 2 (50 points): 1≤N≤10001\le N\le1000; −105≤x,y≤105-10^5\le x,y\le10^5; 1≤S≤1091\le S\le10^9; each maze row contains NN characters from #, .; the starting cell and at least one adjacent cell are unblocked.

Examples

Example 1

Input

4 3 5 9
###.
#...
#..#
##.#

Output

2 3

Explanation: The robot starts at (3,5)(3,5), outside the maze. It turns left whenever a blockage is ahead and continues moving. Its coordinates after seconds 11 through 99 are (3,4)(3,4), (3,3)(3,3), (3,2)(3,2), (2,2)(2,2), (2,3)(2,3), (3,3)(3,3), (3,2)(3,2), (2,2)(2,2) and (2,3)(2,3). Thus its location after 99 seconds is (2,3)(2,3).

Example 2

Input

3 2 5 7
###
#..
#..

Output

2 6

Explanation: The robot starts at (2,5)(2,5) and successively reaches (2,4)(2,4), (2,3)(2,3), (2,2)(2,2), (2,3)(2,3), (2,4)(2,4), (2,5)(2,5), and (2,6)(2,6) after seconds 11 through 77. The last cell is outside the maze.