Post

[BOJ] 1149. RGB๊ฑฐ๋ฆฌ(python)

๐Ÿ“Œ๋ฌธ์ œ

Alt text

๐Ÿ’ช์•„์ด๋””์–ด

  1. ์ƒ‰์น ํ•˜๊ธฐ
    ํ˜„์žฌ ์ง‘๊ณผ ์ƒ‰๊น”์ด ๊ฒน์น˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ด์ „์ง‘์—์„œ ์ƒ‰์น ํ•œ ์ƒ‰๊น” ์ค‘ ์‹ผ ๊ฒƒ์œผ๋กœ ์น ํ•œ๋‹ค.

๐Ÿฅ‚์ฝ”๋“œ

1
2
3
4
5
6
7
8
9
10
11
12
13
import sys; input = sys.stdin.readline

n = int(input())
paint = []
for _ in range(n):
    paint.append(list(map(int,input().split())))

for i in range(1,n):
    paint[i][0]+=min(paint[i-1][1],paint[i-1][2])
    paint[i][1]+=min(paint[i-1][0],paint[i-1][2])
    paint[i][2]+=min(paint[i-1][0],paint[i-1][1])

print(min(paint[-1]))
This post is licensed under CC BY 4.0 by the author.

Comments powered by Disqus.