๐Ÿถ ๋ฌผํ†ต

๋ฐฑ์ค€ Gold5

๋ฌผํ†ต

๋ฌธ์ œ


๊ฐ๊ฐ ๋ถ€ํ”ผ๊ฐ€ A, B, C(1โ‰คA, B, Cโ‰ค200) ๋ฆฌํ„ฐ์ธ ์„ธ ๊ฐœ์˜ ๋ฌผํ†ต์ด ์žˆ๋‹ค. ์ฒ˜์Œ์—๋Š” ์•ž์˜ ๋‘ ๋ฌผํ†ต์€ ๋น„์–ด ์žˆ๊ณ , ์„ธ ๋ฒˆ์งธ ๋ฌผํ†ต์€ ๊ฐ€๋“(C ๋ฆฌํ„ฐ) ์ฐจ ์žˆ๋‹ค. ์ด์ œ ์–ด๋–ค ๋ฌผํ†ต์— ๋“ค์–ด์žˆ๋Š” ๋ฌผ์„ ๋‹ค๋ฅธ ๋ฌผํ†ต์œผ๋กœ ์Ÿ์•„ ๋ถ€์„ ์ˆ˜ ์žˆ๋Š”๋ฐ, ์ด๋•Œ์—๋Š” ํ•œ ๋ฌผํ†ต์ด ๋น„๊ฑฐ๋‚˜, ๋‹ค๋ฅธ ํ•œ ๋ฌผํ†ต์ด ๊ฐ€๋“ ์ฐฐ ๋•Œ๊นŒ์ง€ ๋ฌผ์„ ๋ถ€์„ ์ˆ˜ ์žˆ๋‹ค. ์ด ๊ณผ์ •์—์„œ ์†์‹ค๋˜๋Š” ๋ฌผ์€ ์—†๋‹ค๊ณ  ๊ฐ€์ •ํ•œ๋‹ค.

์ด์™€ ๊ฐ™์€ ๊ณผ์ •์„ ๊ฑฐ์น˜๋‹ค๋ณด๋ฉด ์„ธ ๋ฒˆ์งธ ๋ฌผํ†ต(์šฉ๋Ÿ‰์ด C์ธ)์— ๋‹ด๊ฒจ์žˆ๋Š” ๋ฌผ์˜ ์–‘์ด ๋ณ€ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ๋ฌผํ†ต(์šฉ๋Ÿ‰์ด A์ธ)์ด ๋น„์–ด ์žˆ์„ ๋•Œ, ์„ธ ๋ฒˆ์งธ ๋ฌผํ†ต(์šฉ๋Ÿ‰์ด C์ธ)์— ๋‹ด๊ฒจ์žˆ์„ ์ˆ˜ ์žˆ๋Š” ๋ฌผ์˜ ์–‘์„ ๋ชจ๋‘ ๊ตฌํ•ด๋‚ด๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

์ž…๋ ฅ


์ฒซ์งธ ์ค„์— ์„ธ ์ •์ˆ˜ A, B, C๊ฐ€ ์ฃผ์–ด์ง„๋‹ค.

์ถœ๋ ฅ


์ฒซ์งธ ์ค„์— ๊ณต๋ฐฑ์œผ๋กœ ๊ตฌ๋ถ„ํ•˜์—ฌ ๋‹ต์„ ์ถœ๋ ฅํ•œ๋‹ค. ๊ฐ ์šฉ๋Ÿ‰์€ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•œ๋‹ค.

์˜ˆ์ œ ์ž…๋ ฅ 1

8 9 10

์˜ˆ์ œ ์ถœ๋ ฅ 1

1 2 8 9 10

๐Ÿ“– ๊ฐ€์ ธ๋‹ค ์“ฐ๊ธฐ

๊ฒฐ๋ก ์ ์œผ๋กœ ๋งํ•˜๋ฉด [๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰]์„ ์‚ฌ์šฉํ•˜์—ฌ ํ’€์–ด์•ผ ํ•œ๋‹ค. ๋ชจ๋“  ๊ทธ๋ž˜ํ”„๋ฅผ ํƒ์ƒ‰ํ•ด์•ผ ํ•˜๋ฏ€๋กœ BFS,DFS ๋ฌด์—‡์„ ์‚ฌ์šฉํ•˜๋“  ์ƒ๊ด€ ์—†๋‹ค.

๋‚˜๋Š” ์•„์ง๊นŒ์ง€๋„ ์ด ๋ฌธ์ œ๊ฐ€ ์™œ ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰ ๋ฌธ์ œ์ธ์ง€ ์ดํ•ด๊ฐ€ ๊ฐ€์ง€ ์•Š๋Š”๋‹ค. ๋…ผ๋ฆฌ ์ง„ํ–‰ ๊ณผ์ •์€ ์†”๋ฃจ์…˜์„ ํ†ตํ•˜์—ฌ ์ดํ•ด๋ฅผ ํ•˜์˜€์ง€๋งŒ ์–ด๋–ป๊ฒŒ ํ•˜๋ฉด ์ด ๋ฌธ์ œ๋ฅผ ๋ณด๊ณ  ๊ทธ๋ž˜ํ”„ ํƒ์ƒ‰์ด๋ผ๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ๋– ์˜ฌ๋ฆด ์ˆ˜ ์žˆ์„๊นŒ? ์„ผ์Šค์ธ๊ฑด๊ฐ€.. ๐Ÿ˜ญ

์ด ์งˆ๋ฌธ์€ ์Šคํ„ฐ๋”” ๋ฉค๋ฒ„๋“ค๊ณผ ๊ฐ™์ด ํ† ๋ก ์„ ํ•ด๋ณด์•„์•ผ๊ฒ ๋‹ค.

๐Ÿ“ ๊ณผ์ • ์„ค๊ณ„/๊ด€๋ฆฌ ๐Ÿ”—

๋ช…์พŒํ•˜๊ณ  ๊น”๋”ํ•˜๊ฒŒ ํ‘ผ ์‚ฌ๋žŒ์ด ์žˆ์–ด์„œ ๋‚ด์šฉ์„ ๊ฐ€์ ธ์™€ ๋ณด์•˜๋‹ค.

แ„‰แ…ณแ„แ…ณแ„…แ…ตแ†ซแ„‰แ…ฃแ†บ 2022-08-02 แ„‹แ…ฉแ„’แ…ฎ 5 15 58

แ„‚แ…ฉแ„แ…ณแ„‡แ…ฎแ†จ-7 แ„‚แ…ฉแ„แ…ณแ„‡แ…ฎแ†จ-8

CODE

from collections import deque
import sys
input = sys.stdin.readline

def pour(x,y):
    if not visited[x][y]:
        visited[x][y] = True
        q.append((x,y))

def bfs():
    while q:
        x,y = q.popleft()
        z = c-x-y

        if x == 0:
            result.append(z)

        # A --> B
        water = min(x,b-y)
        pour(x-water,y+water)

        # A --> C
        water = min(x,c-z)
        pour(x-water,y)

        # B --> A
        water = min(y,a-x)
        pour(x+water,y-water)

        # B --> C
        water = min(y,c-z)
        pour(x,y-water)

        # C --> A
        water = min(z,a-x)
        pour(x+water,y)

        # C --> B
        water = min(z,b-y)
        pour(x,y+water)

a,b,c = map(int,input().split())
visited = [[False]*(b+1) for _ in range(a+1)]
visited[0][0] = True
q = deque([(0,0)])
result = []

bfs()
result.sort()
print(*result)

ยฉ 2022. All rights reserved.

Powered by Hydejack v9.1.6