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

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

Grid

면접 대비

시간 제한2초메모리 제한256 MB

요약
각 칸에 한 사람이 네 방향 중 하나를 바라보고 있을 때, 이웃한 두 사람이 마주 보지 않도록 90도 회전 횟수를 최소로 하는 문제입니다.
난이도

보통10점 중 6점

유형
동적 계획법, 그리디, 비트 연산, 구현
정답자
아직 제출이 없습니다

문제

There is a city square in one country which looks exactly like a rectangular N×MN \times M grid. The government decided to hold a meeting of its supporters, so right now, the city square is full of people. More precisely, there is exactly one person in each cell of the grid.

Each person looks in one of the four cardinal directions: notrh, east, south, or west. But when two neighboring people look directly at each other, they get embarrassed because they know that they came to the meeting only to get paid.

The government is well aware of the situation, and so it doesn't want any pair of people to get embarrassed, because if there are enough people who understand that they came for a wrong reason, they can start a riot. Still, the meeting participants are greedy, so they will gladly turn 9090 degrees in any desired direction any time they get paid 11 turning coin. Each person can be paid and turned several times.

The government wants to turn people in such way that in the resulting position, no two persons get embarrassed by looking directly at each other. Your task is to achieve that with the minimum amount of money spent.

입력

The first line of input contains two integers NN and MM, the dimensions of the grid (1≤N,M≤501 \le N, M \le 50). Each of the next NN lines describes one row of the grid. Each of these lines contains MM characters denoting the direction in which the persons are looking. Each of the characters is one of "^" (for notrh), ">" (for east), "v" (for south), or "<" (for west).

출력

Print the minimum amount of turning coins the government has to spend to avoid people getting embarrassed.

예제2

  1. 예제 1

    입력
    3 3
    >v<
    >^<
    ^^^
    
    
    예상 출력
    2
    
  2. 예제 2

    입력
    1 10
    >>><<<>><<
    
    예상 출력
    2