아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Rafting Trip

면접 대비

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

요약
강 방향을 따라 이동하는 래프팅 경로를 강 칸에서 시작할 때, 육지에 닿거나 격자를 벗어나거나 이미 지난 강 칸에 들어가기 전까지 인접한 관광 명소를 가장 많이 방문하는 시작 칸을 찾는다.
난이도

보통10점 중 5점

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

문제

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 rr and cc (2≤r,c≤5002 \leq r, c \leq 500); the terrain grid has rr rows and cc columns.

Each of the next rr lines contains cc 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.

힌트

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

예제2

  1. 예제 1

    입력
    5 6
    v<<<#v
    v#v<.>
    >>v<<<
    ..v##^
    #<<<.^
    
    예상 출력
    4
    
  2. 예제 2

    입력
    4 5
    >v<<.
    ^<..#
    #...#
    .#>^#
    
    예상 출력
    2