<๋ฌธ์ ๋งํฌ>
https://www.acmicpc.net/problem/27942
27942๋ฒ: :danceplant:
์ฒซ์งธ ์ค์ ๊ฐ์ง๊ฐ ๋ชธ์ ๋์ด๋ฉฐ ๋จน์ ์๋ถ์ ์ด๋์ ์ถ๋ ฅํ๋ค. ๋์งธ ์ค์ ๊ฐ์ง๊ฐ ๋ชธ์ ๋์ธ ๋ฐฉํฅ์ ๋ํ๋ด๋ ๋ฌธ์๋ฅผ ๋์ธ ์์๋๋ก ํ ์ค์ ์ถ๋ ฅํ๋ค. ์ํ์ข์ฐ๋ ๊ฐ๊ฐ UDLR์ ๋์๋๋ค.
www.acmicpc.net
<ํ์ด ์ ๋ต>
1. ์๋ฎฌ๋ ์ด์ / ๋์ ํฉ ๋ฌธ์ ์ ๋๋ค.
2. java๋ c++์ ๋จ์ ๊ตฌํ์ผ๋ก๋ ํต๊ณผ๊ฐ ๋ ๊ฒ ๊ฐ์๋ฐ python๊ธฐ์ค์ผ๋ก๋ ์๊ฐ์ด๊ณผ๊ฐ ๋ฐ์ํ๊ณ pypy๋ก ํต๊ณผ๊ฐ ๋ฉ๋๋ค.
3. ์ ๋ ๋จ์ ์๋ฎฌ๋ ์ด์ ์ผ๋ก ํ์์ง๋ง, ๋์ ํฉ ์๊ณ ๋ฆฌ์ฆ์ ํ์ฉํด ์ด๊ธฐ์ ์ ๋ ฅ ๋ฐ์ ๋ฐฐ์ด์ ๋์ ํฉ ๋ฐฐ์ด๋ก ๋ณํํ๊ณ ์์๋ถ ์ญ์ทจ๋ฅผ ์ผ์ผํ ๋ํ๋ ๊ฒ ์๋๋ผ ํด๋น ํ / ์ด์์ ๊ตฌ๊ฐํฉ๋ง ๋ํด์ฃผ๋ฉด ํ์ด์ฌ์ผ๋ก๋ ์๊ฐ ๋ด์ ํต๊ณผ๊ฐ ๋ ๊ฒ์ ๋๋ค.
<์ ๋ต ์ฝ๋>
import sys, os, io, atexit
input = lambda: sys.stdin.readline().rstrip('\r\n')
stdout = io.BytesIO()
sys.stdout.write = lambda s: stdout.write(s.encode("ascii"))
atexit.register(lambda: os.write(1, stdout.getvalue()))
# 230411 27942 :danceplant:
# ์ ๋ต์ฝ๋
dir_dict = {
"U": [(-1, 0), (0, 0)],
"D": [(0, 0), (1, 0)],
"L": [(0, -1), (0, 0)],
"R": [(0, 0), (0, 1)]
}
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
points = [[N // 2 - 1, N // 2 - 1], [N // 2, N // 2]]
ans = 0
path = ''
flag = True
while True:
dir = ""
total = 0
# ์
if points[0][0] - 1 >= 0:
up_total = 0
for i in range(points[0][1], points[1][1] + 1):
up_total += arr[points[0][0] - 1][i]
if up_total > 0:
total = up_total
dir = "U"
# ์๋
if points[1][0] + 1 < N:
down_total = 0
for i in range(points[0][1], points[1][1] + 1):
down_total += arr[points[1][0] + 1][i]
if down_total > total:
total = down_total
dir = "D"
# ์ผ
if points[0][1] - 1 >= 0:
left_total = 0
for i in range(points[0][0], points[1][0] + 1):
left_total += arr[i][points[0][1] - 1]
if left_total > total:
total = left_total
dir = "L"
# ์ค
if points[1][1] + 1 < N:
right_total = 0
for i in range(points[0][0], points[1][0] + 1):
right_total += arr[i][points[1][1] + 1]
if right_total > total:
total = right_total
dir = "R"
if total == 0:
break
ans += total
path += dir
for i in range(2):
for j in range(2):
points[i][j] += dir_dict[dir][i][j]
print(ans)
print(path)
'โญ Problem_Solving > ๋ฐฑ์ค' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค] 20165 ์ธ๋ด์ ๋๋ฏธ๋ ธ ์ฅ์ธ ํธ์ (Python/ํ์ด์ฌ) (0) | 2023.05.14 |
---|---|
[๋ฐฑ์ค] 1421 ๋๋ฌด๊พผ ์ด๋ค์ (Python/ํ์ด์ฌ) (2) | 2023.05.08 |
[๋ฐฑ์ค] 17070 ํ์ดํ ์ฎ๊ธฐ๊ธฐ1 (Python/ํ์ด์ฌ) (0) | 2023.04.04 |
[๋ฐฑ์ค] 2072 ์ค๋ชฉ (Python/ํ์ด์ฌ) (1) | 2022.12.28 |
[๋ฐฑ์ค] 5635 ์์ผ (Python/ํ์ด์ฌ) (2) | 2022.12.18 |
๋๊ธ