Skip to content

Commit

Permalink
리뷰 풀이
Browse files Browse the repository at this point in the history
  • Loading branch information
JangHongJoon committed Mar 3, 2024
1 parent eaebe4f commit a28884c
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-18258.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
elif 'back' == _str[0] :
if len(queue) == 0 : print(-1)
else : print(queue[len(queue)-1])

queue.pop(0)

82 changes: 82 additions & 0 deletions wkdghdwns199/리뷰풀이/ACM-3197.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
from collections import deque
import sys
input = sys.stdin.readline



def waterMelt() :
while waterPos :
y,x = waterPos.popleft()
maps[y][x] = '.'

for dy,dx in dir :
ny,nx = y+dy, x+dx
if 0<=ny < r and 0 <= nx <c and not waterCheck[ny][nx] :
if maps[ny][nx] == '.' :
waterPos.append((ny,nx))
elif maps[ny][nx] == 'X' :
nextWaterPos.append((ny,nx))
waterCheck[ny][nx] = True

def findSwan() :
while swanPos :
y,x = swanPos.popleft()

if y == endY and x == endX :
return True


for dy,dx in dir :
ny,nx = y + dy, x + dx
if 0<= ny < r and 0 <= nx < c and not swanCheck[ny][nx] :
if maps[ny][nx] == '.':
swanPos.append((ny,nx))
elif maps[ny][nx] == 'X' :
nextSwanPos.append((ny,nx))
swanCheck[ny][nx] = True
return False


r,c = map(int, input().split())
maps = [list(input().strip()) for _ in range(r)]
swanCheck = [[False] * c for _ in range(r)]
waterCheck = [[False] * c for _ in range(r)]
dir = [[1,0], [-1,0], [0,1], [0,-1]]

swanPos = deque()
nextSwanPos = deque()
waterPos = deque()
nextWaterPos = deque()


for i in range(r):
for j in range(c):
if maps[i][j] =='L' :
if not swanPos :
swanPos.append((i,j))
swanCheck[i][j] = True
else :
endY, endX = i,j
maps[i][j] = '.'

waterPos.append((i,j))
waterCheck[i][j] = True
elif maps[i][j] == '.':
waterPos.append((i,j))
waterCheck[i][j] = True


days =0
while True :
waterMelt()
if findSwan() : break

swanPos = nextSwanPos
waterPos = nextWaterPos
nextSwanPos = deque()
nextWaterPos = deque()

days+=1

print(days)

0 comments on commit a28884c

Please sign in to comment.