-
Notifications
You must be signed in to change notification settings - Fork 1
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
12-alstjr7437 #41
12-alstjr7437 #41
Conversation
νλ 5 μ-μ |
νμ€ν λ€λ₯Έ μ¬λλ€μ΄ μ μΆν μ½λ 보λκΉ ν 2κ°λ₯Ό μ°λ νμ΄κ° λ§λλΌκ΅¬μ. μ κ²½μ° μ λμ¨ νμΈλλ₯Ό μ΄μ©ν΄μ νμμ΅λλ€. λ°±μ‘°μ νΈμ μ PRμ κ·Έλ¦Ό μλ£ κ°μ΄ 첨λΆν΄λ¨μΌλ ν λ² νμΈν΄λ³΄μΈμ~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ν λ€μ bfs νλ‘ λ겨주λ건 μκ° λͺ»νλλ°..
μ§μ νμ΄λ³Ό μλκ° μλμ μ€λͺ
보면μ, μ½λλ₯Ό λ°λΌμΉλ©΄μ λ΄€μ΅λλΉ..
κΌΌκΌΌνκ² PR μ¬λ €μ£Όμ
μ κ°μ¬ν©λλ€!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
보λκΉ queue 4κ° μ¨μ νΈλ μ¬λλ μλλΌκ΅¬μ.
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)
|
π λ¬Έμ λ§ν¬
λ°±μ‘°μ νΈμ
βοΈ μμλ μκ°
4μκ°
(λ²λ¦° μκ° 2μκ° 30λΆ)νλ λ¬Έμ μΉκ³ μ½λ€κΈΈλ λμ μ νλλ°...
μκ° μ΄κ³Όλ μκ°μ μνλ©΄ μ νλ Έλλ° μκ° μ΄κ³Όκ° λ¨λκΉ λ¨Έλ¦¬κ° βͺοΈμ΄ λμ΅λλ€..
π§ νλ¦° λΆλΆ
μ°μ λ¬Έμ μμ ν루μ νλμ© μΌμμ μ§μλκ°λ λΆλΆμ λ리κ³
μμ λΆλΆμ λλ¦¬κ³ λ νμ λ°±μ‘°κ° λ§λ μ μλμ§ ν μ€νΈνλ©΄ λκ² λλΌκ΅¬μ!
κ·Έλμ λμ¨λΆλΆμ΄ λ§€λ² visitedλ₯Ό λ§€λ² μ΄κΈ°νν΄μ 맀μΌλ§€μΌ λ리λ λΆλΆμ΄μμ΅λλ€!
μ 체 νΈμ λ°μμ€κΈ°
νλμ© μΌμ μμ λ ν¨μ λ§λ€κΈ°
λ°±μ‘° λ§λλμ§ μ²΄ν¬νλ ν¨μ λ§λ€κΈ°
whileλ¬ΈμΌλ‘ 2~3λ²μ κ³μν΄μ λμκ°λ©΄μ river μ΅μ ν ν΄μ£ΌκΈ°
μμ κ°μ΄ μ΄λμ λ μ΄λ»κ² λμκ°μΌν μ§ λ§λ€μ΄μ§κ³ μλμ κ°μ΄ μ½λλ₯Ό μ§―μ΅λλ€!
κ·Όλ° μμ κ°μ΄ νκ²λλ©΄ μκ°μ΄κ³Όκ° λμ€λλΌκ΅¬μ
λμμ λ€μ μκ°ν΄λ³΄λ
μΌμμ λΆμ λλ riverμ λͺ¨λ λΆλΆμ λ리면μ μκ° π
λ°±μ‘° λ§λλμ§ μ²΄ν¬ν λλ λͺ¨λ λΆλΆμ λ€μ νμΈν΄μΌν΄μ μκ° π
μ΄λ κ² μ¬λ¬κ°μ§ μκ° μ΄κ³Όλ₯Ό ν λ§ν μ½λλ₯Ό μμ±νμμ΅λλ€.
βοΈ μ λ΅
μμ κ°μ΄ 1, 2, 3, 4λ‘
μΌμμ λΆμκ³ λ°±μ‘°κ° λ§λλμ§ μ²΄ν¬νλ λΆλΆμ λκ°μ§λ§
νλ² BFSλ₯Ό ν λΆλΆμ λ€μ μΈμΌμ΄ μκ³ μκ° λλΉλ§ λμ΅λλ€!!
κ·Έλμ μκ°ν λΆλΆμ΄ μλ°©ν₯ νλ₯Ό μ΄μ©ν΄ μ¬μ¬μ©μ μμ λ©΄ λμ΅λλ€!
π§ μΌμ κΉ¨μ§λ λΆλΆ
μ νμ κ°μ΄ μμ§κ² λλλ°
λ°λ‘ .λΆλΆμ λ€μ λ릴 νμ μμ΄
Xλ©΄ 2λ²μ§Έ νμ λ£μ΄μ£Όλ©΄ λμ΅λλ€.
μ ν μμ λ₯Ό λ€λ©΄
water1 -> 0, 1, 6, 7
water2 -> 2, 5
water1 -> 2, 5
water2 -> 3, 4
water 1 -> 3, 4
μ΄λ κ² ν΄μ λͺ¨λ μΌμμ΄ κΉ¨μ§κ² λ©λλ€!!!
π¦’ λ°±μ‘° λ§λλμ§ μ²΄ν¬νκΈ°
μ΄λΆλΆλ μμ λκ°μ λ°©μμΌλ‘ κ°μ§λ§ μ²μ λ£μ λ°±μ‘°λΆλΆλΆν° μμν©λλ€.
κ·Έλ¦¬κ³ μμ κ°μ΄ μ§ννλ©΄μ λ°±μ‘°κ° 0,1μ μμΌλ 0,1μ popν΄μ£Όκ³ μ£Όλ³ λΆλΆμ λ£μ΄μ€λλ€.
swan1 -> 0, 1
swan2 -> 2
swan1 -> 2
swan2 -> 3
swan1 -> 3, 4, 5, 6, 7
λͺ¨λ .μΌλ‘ swan1μ λ€ pushλκ³ λ€λ₯Έ λ°±μ‘°μ μ’νλ₯Ό λ§λκ² λ©λλ€.
π» μ΅μ’ μ½λ
π μλ‘κ² μκ²λ λ΄μ©
μ΄λ»κ² ꡬνκΉμ§λ μ½κ² νλ Έλλ° μκ°μ΄κ³Ό λ©λͺ¨λ¦¬ μ΄κ³Ό κ³μ°μ μνλκΉ μ λ§ λ©λΆμ΄λ€μ...
κ·Έλλ μλ°©ν₯ νλ₯Ό μ΄μ©ν΄μ μ¬μ¬μ© μκ°μ μ€μ΄λ λΆλΆμ μ°μ΅ν μ μμ΄μ μ’μμ΅λλ€!