๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 18242๋ฒ
ํ์ด ๊ณผ์
๋ค๋ชจ๋ค๋ชจ ์๊ณผ์ ์๋ ฅ ๊ฒ์ฌ๋ฅผ ํต๊ณผํ ์ ์๋ ๊ธฐ๋ฅ์ ๊ตฌํํ๋ ๋ฌธ์ ์
๋๋ค.
๊ฒฉ์์๋ ๋จ ํ๋์ ์ง์ฌ๊ฐํ์ด ์กด์ฌํ๋ค๋ ๋ณด์ฅ์ด ์๊ธฐ ๋๋ฌธ์
์ฐ๋ฆฌ๊ฐ ํ์ฉํ ์ ์๋ ์ฒซ๋ฒ์งธ ์ ๋ณด๋ ์ผ์ชฝ ์๋จ ๋ชจ์๋ฆฌ์ ์์น์
๋๋ค.
์ดํ ์ค๋ฅธ์ชฝ ์๋จ ๋ชจ์๋ฆฌ์ ์ผ์ชฝ ํ๋จ ๋ชจ์๋ฆฌ์ ์์น๋ฅผ ๊ตฌํด์ ์ง์ฌ๊ฐํ์ ๋๋น์ ๋์ด๋ฅผ ๊ตฌํ๊ณ
์ด๋ฅผ ํ์ฉํด ์ง์ฌ๊ฐํ์ ๊ฐ ๋ณ์ ๊ฒ์ฌํ๋ฉด ๋ฉ๋๋ค.
์ฝ๋
import sys
N, M = list(map(int, sys.stdin.readline().split()))
board = [list(sys.stdin.readline().strip()) for _ in range(N)]
def get_pivot(board):
pivot = None
for x in range(N):
for y in range(M):
if board[x][y] == '#':
pivot = [x, y]
break
if pivot is not None:
break
return pivot
def get_width_height(board, sx, sy):
right_top, bottom_left = [], []
# ์ค๋ฅธ์ชฝ ์๋จ ๋ชจ์๋ฆฌ ์ฐพ๊ธฐ
for y in range(M - 1, sy, -1):
if board[sx][y] == '#':
right_top = [sx, y]
break
# ์ผ์ชฝ ํ๋จ ๋ชจ์๋ฆฌ ์ฐพ๊ธฐ
for x in range(N - 1, sx, -1):
if board[x][sy] == '#':
bottom_left = [x, sy]
break
width = right_top[1] - sy + 1
height = bottom_left[0] - sx + 1
return width, height
def inspect_board(board, width, height, sx, sy):
# UP, DOWN
for y in range(sy, sy + width):
if board[sx][y] == '.':
return 'UP'
if board[sx + height - 1][y] == '.':
return 'DOWN'
# LEFT, RIGHT
for x in range(sx, sx + height):
if board[x][sy] == '.':
return 'LEFT'
if board[x][sy + width - 1] == '.':
return 'RIGHT'
def solution():
pivot = get_pivot(board)
width, height = get_width_height(board, *pivot)
answer = inspect_board(board, width, height, *pivot)
return answer
print(solution())
๋ฐ์ํ
'๐ algorithm > boj' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ 20044 - Project Teams (0) | 2021.03.08 |
---|---|
BOJ 1644 - ์์์ ์ฐ์ํฉ (0) | 2021.03.08 |
BOJ 9184 - ์ ๋๋ ํจ์ ์คํ (0) | 2021.03.08 |
BOJ 14226 - ์ด๋ชจํฐ์ฝ (0) | 2021.03.08 |
BOJ 2529 - ๋ถ๋ฑํธ (0) | 2021.03.08 |
๐ฌ ๋๊ธ