/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 266 点
問題文
高橋君は H 行 W 列のグリッド上に並んだマスからなる街を散策しています。上から i 行目、左から j 列目のマスを (i, j) と表します。行番号は北から南へ、列番号は西から東へ大きくなります。
各マスには道案内の標識が立てられており、南向きの矢印 v または東向きの矢印 > のいずれかが表示されています。i 行目の各マスの標識は文字列 S_i で表され、S_i の j 文字目がマス (i, j) の標識に対応します。
高橋君は北西の角にあるマス (1, 1) からスタートし、以下のルールに従って繰り返し移動します。
- 現在マス (i, j) にいるとき、そのマスの標識が
v(南向き)ならば、マス (i+1, j) へ移動しようとします。 - 現在マス (i, j) にいるとき、そのマスの標識が
>(東向き)ならば、マス (i, j+1) へ移動しようとします。
移動先がグリッドの外である場合、高橋君はその移動を行わず、現在いるマスで停止します。具体的には、現在マス (i, j) にいるとき、南へ移動しようとして i + 1 > H となる場合、または東へ移動しようとして j + 1 > W となる場合に、高橋君は停止します。
移動は常に南または東への 1 マスのみであるため、高橋君は (1, 1) から南方向に最大 H - 1 回、東方向に最大 W - 1 回しか移動できず、スタートから H + W - 2 回以内の移動で必ず停止します。
高橋君が停止したマスの座標を求めてください。
制約
- 1 \leq H \leq 500
- 1 \leq W \leq 500
- H, W は整数
- S_i は
vおよび>のみからなる長さ W の文字列である
入力
H W S_1 S_2 \vdots S_H
- 1 行目には、グリッドの行数を表す整数 H と列数を表す整数 W が、スペース区切りで与えられる。
- 続く H 行にわたって、グリッドの各行の情報が文字列として与えられる。i 行目 (1 \leq i \leq H) の情報は入力の i + 1 行目に与えられ、長さ W の文字列 S_i である。S_i の j 文字目は、マス (i, j) に表示された標識を表し、
v(南向き)または>(東向き)のいずれかである。
出力
高橋君が停止したマスの行番号と列番号を、スペース区切りで 1 行で出力せよ。すなわち、停止したマスが (r, c) であるとき、r と c をスペース区切りで出力せよ。
入力例 1
3 3 v>v vv> >>>
出力例 1
3 3
入力例 2
3 4 >>>v vv>v >v>>
出力例 2
3 4
入力例 3
5 6 v>>v>> >v>>v> v>v>>v >>vv>> vv>>v>
出力例 3
5 5
入力例 4
8 10 >>v>>>v>>> v>v>>v>v>> >>v>v>>>v> v>>>v>v>>v >v>>v>>>v> v>v>>>v>>v >>v>v>>v>> v>>>v>>>>>
出力例 4
8 10
入力例 5
1 1 v
出力例 5
1 1
Score : 266 pts
Problem Statement
Takahashi is exploring a town consisting of cells arranged in a grid with H rows and W columns. The cell at the i-th row from the top and the j-th column from the left is denoted as (i, j). Row numbers increase from north to south, and column numbers increase from west to east.
Each cell has a directional signpost displaying either a south-pointing arrow v or an east-pointing arrow >. The signposts for the cells in the i-th row are represented by the string S_i, where the j-th character of S_i corresponds to the signpost at cell (i, j).
Takahashi starts at cell (1, 1) in the northwest corner and repeatedly moves according to the following rules:
- If he is currently at cell (i, j) and the signpost on that cell is
v(south-pointing), he attempts to move to cell (i+1, j). - If he is currently at cell (i, j) and the signpost on that cell is
>(east-pointing), he attempts to move to cell (i, j+1).
If the destination is outside the grid, Takahashi does not make that move and stops at his current cell. Specifically, if he is at cell (i, j) and attempts to move south but i + 1 > H, or attempts to move east but j + 1 > W, Takahashi stops.
Since each move is always exactly one cell to the south or east, Takahashi can move at most H - 1 times southward and at most W - 1 times eastward from (1, 1), so he will always stop within H + W - 2 moves from the start.
Determine the coordinates of the cell where Takahashi stops.
Constraints
- 1 \leq H \leq 500
- 1 \leq W \leq 500
- H, W are integers
- S_i is a string of length W consisting only of
vand>
Input
H W S_1 S_2 \vdots S_H
- The first line contains an integer H representing the number of rows and an integer W representing the number of columns of the grid, separated by a space.
- The following H lines provide the information for each row of the grid as a string. The information for the i-th row (1 \leq i \leq H) is given on the (i + 1)-th line of the input as a string S_i of length W. The j-th character of S_i represents the signpost displayed at cell (i, j), which is either
v(south-pointing) or>(east-pointing).
Output
Output the row number and column number of the cell where Takahashi stops, separated by a space, on a single line. That is, if the cell where he stops is (r, c), output r and c separated by a space.
Sample Input 1
3 3 v>v vv> >>>
Sample Output 1
3 3
Sample Input 2
3 4 >>>v vv>v >v>>
Sample Output 2
3 4
Sample Input 3
5 6 v>>v>> >v>>v> v>v>>v >>vv>> vv>>v>
Sample Output 3
5 5
Sample Input 4
8 10 >>v>>>v>>> v>v>>v>v>> >>v>v>>>v> v>>>v>v>>v >v>>v>>>v> v>v>>>v>>v >>v>v>>v>> v>>>v>>>>>
Sample Output 4
8 10
Sample Input 5
1 1 v
Sample Output 5
1 1