Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[23-09-10] jamin.py #316

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions Baekjoon - 문제풀이/RGB거리/jamin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
n = int(input())
RGB = []
for i in range(n):
RGB.append(list(map(int,input().split())))

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

print(min(RGB[n-1][0],RGB[n-1][1],RGB[n-1][2]))
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import sys
from heapq import heappush,heappop
input = sys.stdin.readline
dx = [-1,1,0,0]
dy = [0,0,-1,1]

case = 1

while True:
N = int(input())
if N == 0:
break
cave = [list(map(int,input().split())) for _ in range(N)]
visited = [[-1 for _ in range(N)]for _ in range(N)]
heap = []
heappush(heap,[cave[0][0],0,0])
visited[0][0] = 0
while heap:
answer,x,y = heappop(heap)
if [x,y] == [N-1,N-1]:
print("Problem",case,end = "")
print(":",answer)
for i in range(4):
ax = x + dx[i]
ay = y + dy[i]
if 0<= ax < N and 0 <= ay < N:
if visited[ax][ay] == -1:
heappush(heap, [answer+cave[ax][ay],ax,ay])
visited[ax][ay] = 0
case += 1