10157

https://www.acmicpc.net/problem/10157

  1. ๊ฐ„๋‹จํ•œ๋ฐ ํ‘ธ๋Š”๋ฐ ์˜ค๋ž˜๊ฑธ๋ฆฐ DFS ๋ฌธ์ œ ( ์™œ ์˜ค๋ž˜ ๊ฑธ๋ ธ๋Š”์ง€๋Š” ๋’ค์— ๋‚˜์˜ด..)

  2. ์ตœ์•…์˜ ๊ฒฝ์šฐ 1์–ต๋ฒˆ๊นŒ์ง€ ๊ณ„์‚ฐํ•ด์•ผํ•˜๊ธฐ ๋•Œ๋ฌธ์— DFS ๋ฅผ ์žฌ๊ท€๋กœ ๋ง๊ณ  ๋ฐ˜๋ณต๋ฌธ์œผ๋กœ ๊ตฌํ˜„ํ•˜์ž !

  3. ์ธ๋ฑ์Šค ๋ฒ”์œ„ ๋„˜์–ด๊ฐ€๊ฑฐ๋‚˜ ๋ฐฉ๋ฌธ๋˜์–ด ์žˆ์œผ๋ฉด ๋ฐฉํ–ฅ ํ‹€์–ด์คŒ. ์ˆœ์„œ๋Š” ์ƒ, ์šฐ, ํ•˜, ์ขŒ ์ˆœ์œผ๋กœ ๋ฐ˜๋ณต

  4. ํ•ด๋‹น k์— ๋„๋‹ฌํ•˜๋ฉด ํ˜„์žฌ ์œ„์น˜๋ฅผ ๋ฌธ์ œ์˜ ์ธ๋ฑ์Šค์— ๋งž์ถฐ์„œ ( ์—ด, ํ–‰ ) ์ถœ๋ ฅ

    • ์•„๋‹ˆ ์ธ๋ฑ์‹ฑ์„ ํฌํ•œํ•˜๊ฒŒ ํ•œ ๊ฒƒ๋„ ๋ชจ์ž๋ผ์„œ, ์™œ ( ์—ด, ํ–‰ ) ์œผ๋กœ ๋‚˜ํƒ€๋ƒˆ์„๊นŒ. ์‹ฌ์ง€์–ด TC 30% ๊ฐ€ ํ–‰ = ์—ด ์ธ ๊ฒฝ์šฐ๋กœ ํ•ด๋†”์„œ 30% ๊นŒ์ง€ ์ฑ„์ ์ค‘์ด ๋– ์„œ ๋””๋ฒ„๊น…ํ•  ๋•Œ ํŒŒ์•… ๋ชป ํ•จ.

    • ๋ฌธ์ œ๋ฅผ ์ž˜ ์ฝ์ž ๊ฐ€ ๋งž๊ธด ํ•œ๋ฐ, ์ด ์ˆ˜์ค€์ด ๋งž๊ธด ํ•œ๊ฐ€ ์‹ถ๋‹ค.

c, r = map(int,input().split())

# visited ๊ฐœ๋…์œผ๋กœ ๋งŒ๋“ฆ
a = [[0 for _ in range(c)] for _ in range(r)]
total = c * r

k = int(input())

# ์• ์ดˆ์— ๋ฐฐ์ • ๋ชป ํ•œ๋‹ค๋ฉด ๋จผ์ € 0 ์ถœ๋ ฅ
if k > total:
    print(0)
    exit()

# ์ƒ, ์šฐ, ํ•˜, ์ขŒ
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

d = 0
cnt = 1
stack = [(r - 1, 0)]

while True:
    x, y = stack.pop()

    # ๋ฐฉ๋ฌธ ์ˆ˜ํ–‰
    a[x][y] = 1

    if cnt == k:
        print(y + 1, r - x)
        exit()

    # ๋‹ค์Œ ๊ฐˆ ๊ณณ
    nx = x + dx[d]
    ny = y + dy[d]

    # ์ธ๋ฑ์‹ฑ ๋ฒ—์–ด๋‚˜๊ฑฐ๋‚˜ ๋ฐฉ๋ฌธ๋˜์–ด์žˆ๋‹ค๋ฉด ๋ฐฉํ–ฅ ํ‹€๊ธฐ
    if 0 > nx or r <= nx or 0 > ny or c <= ny or a[nx][ny] == 1:
        d = (d + 1) % 4
        nx = x + dx[d]
        ny = y + dy[d]

    cnt += 1
    stack.append((nx, ny))

Last updated