문제
import sys
from collections import deque
input = sys.stdin.readline
H, W = map(int, input().split())
Map = []
for i in range(H):
Map.append([j for j in input()])
X = [0, -1, 0, 1]
Y = [-1, 0, 1, 0]
NEWS = ['<', '^', '>', 'v']
def start(a, b):
cnt = 0
for i in range(4):
if 0 <= a + X[i] < H and 0 <= b + Y[i] < W and Map[a + X[i]][b + Y[i]] == '#':
news = NEWS[i]
cnt += 1
if cnt > 1:
return False
return news
def robot(a, b):
path = deque()
queue = deque()
queue.append([a, b])
visited[a][b] = True
while queue:
[x, y] = queue.popleft()
for i in range(4):
nx = x + X[i]
ny = y + Y[i]
if 0 <= nx < H and 0 <= ny < W:
if Map[nx][ny] == '#' and visited[nx][ny] == False:
visited[nx][ny] = True
path.append(NEWS[i])
queue.append([nx, ny])
return path
a = 0
b = 0
for x in range(H):
for y in range(W):
if Map[x][y] == '#' and start(x, y):
visited = [[False for i in range(W)] for i in range(H)]
first_news = start(x, y)
path = robot(x, y)
answer = ''
current_path = path.popleft()
cnt = 1
while path:
next_path = path.popleft()
if next_path == current_path:
cnt += 1
current_path = next_path
if cnt % 2 == 0:
answer += 'A'
cnt = 0
else:
if NEWS[NEWS.index(current_path)-1] == next_path:
answer += 'L'
else:
answer += 'R'
current_path = next_path
cnt += 1
print(x+1, y+1)
print(first_news)
print(answer)
sys.exit()