Logo
(追記) (追記ここまで)

25231번 - Rafting Trip 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB136393432.692%

문제

You are planning a rafting trip. The terrain can be viewed as a grid. Each cell is either land, or has part of a river flowing through it in one of the four directions: north, south, east, or west. Some land cells contain a sightseeing spot.

You can choose any river cell as the starting point of your rafting trip. Once your raft reaches a river cell (including the starting cell), it will follow the water direction of that cell and move to an adjacent cell or exit the grid.

You can visit a nearby sightseeing spot if your raft reaches a river cell that is adjacent to it, including the starting cell. (Cell adjacency includes horizontal and vertical neighbors, but not diagonal neighbors.) Each sightseeing spot can be visited at most once.

Your rafting trip stops when your raft moves onto a land cell, exits the grid, or enters a river cell that it has reached before. Note that if the raft ends at a land cell, you cannot visit the sightseeing spots adjacent to that land cell.

What is the maximum number of sightseeing spots you can visit in a single rafting trip if you choose your starting cell optimally?

입력

The first line of input contains two integers $r$ and $c$ (2ドル \leq r, c \leq 500$); the terrain grid has $r$ rows and $c$ columns.

Each of the next $r$ lines contains $c$ characters describing one row of the terrain grid. A dot '.' denotes a land cell without a sightseeing spot. A hash '#' denotes a land cell that contains a sightseeing spot. River cells are denoted by '^' (north), 'v' (south), '>' (east), or '<' (west). There is at least one river cell in the grid.

출력

Output a single line with a single integer, which is the maximum number of sightseeing spots you can visit in a single rafting trip.

제한

예제 입력 1

5 6
v<<<#v
v#v<.>
>>v<<<
..v##^
#<<<.^

예제 출력 1

4

예제 입력 2

4 5
>v<<.
^<..#
#...#
.#>^#

예제 출력 2

2

힌트

Illustration of the first sample case. The optimal rafting trip starts at the cell with the raft and visits 4ドル$ sightseeing spots (marked by binoculars). The river cells reached along the trip are highlighted in dark blue.

출처

ICPC > Regionals > North America > North America Championship > North America Championship 2022 G번

Camp > Petrozavodsk Programming Camp > Summer 2022 > Day 1: Welcome Contest G번

  • 문제를 만든 사람: Bowen Yu
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /