marblemaze

시간 제한1초메모리 제한2048 MB

요약
경사로와 시소로 이루어진 작은 격자에서 N개의 구슬을 순서대로 굴리며 시소의 방향 전환 상태를 추적해 각 구슬이 빠져나가는 위치를 출력한다.
난이도

보통10점 중 6점

유형
시뮬레이션, 구현
정답자
아직 제출이 없습니다

문제

Martin is building a magical marble machine. Marbles roll all around it making majestic music. To make the machine interesting, Martin collects all the marbles into a funnel and then drops them one after another into a square maze assembled on the bottom of the machine.

The maze is a grid of ramps and seesaws. When marbles land on a ramp, they will always roll in the direction the ramp faces. When marbles land on a seesaw, they alternate rolling in two opposite directions. Your job is to figure out where marbles will fall out of the maze so that Martin can catch them before they roll away and get lost.

입력

The first line of input consists of three space-separated integers WW (1≤W≤101 \le W \le 10), HH (1≤H≤101 \le H \le 10), and NN (1≤N≤1001 \le N \le 100) where WW is the width of the grid, HH is the height of the grid, and NN is the number of marbles Martin needs to catch.

The second line of input consists of two integers X_0X\_0 (0≤X_0<W0 \le X\_0 < W) and Y_0Y\_0 (0≤Y_0<H0 \le Y\_0 < H) separated by a space. Martin's funnel will sequentially drop each of the NN marbles onto the ramp or seesaw at the grid position (X_0,Y_0)(X\_0, Y\_0). No two marbles can be in the maze at the same time.

The remainder of the input consists of the grid itself: HH lines of text, each WW characters in length. Every character is one of:

  • "<" -- A ramp that sends marbles leftwards.
  • ">" (greater-than symbol) -- A ramp that sends marbles rightwards.
  • "^" (caret symbol) -- A ramp that sends marbles upward.
  • "v" (lowercase letter V) -- A ramp that sends marbles downwards.
  • "-" (dash) -- A seesaw which sends the 1st marble left, the 2nd right, the 3rd left, and so on.
  • "|" (vertical bar) -- A seesaw which sends the 1st marble up, the 2nd down, the 3rd up, and so on.
  • "." (period) -- A hole in the maze. If a marble lands here, it will fall out.

The character in the upper-left of the grid has position (0,0)(0, 0) and the character in the lower-right has position (W−1,H−1)(W - 1, H - 1). Any ramp, seesaw, or hole yy lines from the start of the grid and xx characters from the start of a line is at position (x,y)(x, y).

It is impossible for any marble to roll forever since that would violate the laws of physics! Each marble will land on each ramp or seesaw at most once before eventually falling through a hole in the maze or off the side of the grid.

출력

Predict the (x,y)(x, y) position where each of the NN marbles will fall through a hole in the maze or off the side of the grid. Then output NN lines, each consisting of the two integers xx (−1≤x≤W-1 \le x \le W) and yy (−1≤y≤H-1 \le y \le H) separated by a space. Each (x,y)(x, y) must be the position of a hole or else one square from the edge of the grid.

예제2

  1. 예제 1

    입력
    3 2 4
    1 0
    .v.
    <->
    
    예상 출력
    -1 1
    3 1
    -1 1
    3 1
    
  2. 예제 2

    입력
    5 3 5
    2 1
    ..>>v
    -.|.-
    ^<<..
    
    예상 출력
    3 1
    -1 1
    5 1
    1 1
    3 1