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

84-tgyuuAn #261

Merged
merged 1 commit into from
Jan 8, 2025
Merged

84-tgyuuAn #261

merged 1 commit into from
Jan 8, 2025

Conversation

tgyuuAn
Copy link
Member

@tgyuuAn tgyuuAn commented Dec 31, 2024

πŸ”— 문제 링크

뢈!

βœ”οΈ μ†Œμš”λœ μ‹œκ°„

30λΆ„

✨ μˆ˜λ„ μ½”λ“œ

image

이 문제λ₯Ό ν’€ λ•Œ 자주 μ‚¬μš©λ˜λŠ” 작기술이 ν•˜λ‚˜ μ‚¬μš©λ˜λŠ”λ°,

문제의 μ΅œμ’… λͺ©μ μ΄ λ°–μœΌλ‘œ λ‚˜κ°ˆ 수 μžˆλƒ 없냐λ₯Ό νŒλ‹¨ν•˜λŠ” κ²ƒμ΄λ―€λ‘œ,

이λ₯Ό μ†μ‰½κ²Œ κ΅¬ν˜„ν•˜λŠ” 방법은 기쑴에 주어진 λ³΄λ“œμ˜ 외곽을 ν•œ 번 κ°μ‹Έμ£ΌλŠ” 것이닀.




사싀 μœ„ 작기술만 ν„°λ“ν•˜λ©΄ λ°”λ‘œ κ³¨λ“œ5 정도 μˆ˜μ€€μ˜ BFS 문제둜 바뀐닀.

μ—¬κΈ°μ„œλ„ μ•„μ£Ό μ‚¬μ†Œν•œ λ””ν…ŒμΌμ΄ λ“€μ–΄κ°€λŠ”λ°,

μ§€ν›ˆμ΄κ°€ 갈 수 μžˆλŠ” κ³³κ³Ό 뢈이 νΌμ§€λŠ” κ³³ 각각 2κ°œμ— 항에 λŒ€ν•΄μ„œ BFSλ₯Ό λŒλ €μ•Όν•˜λŠ”λ°,

이 λ•Œ μ‹ κ²½μ¨μ€˜μ•Ό ν•  점은 뢈이 νΌμ§€λŠ” 곳을 λ¨Όμ € BFSλ₯Ό 돌린 λ’€,

μ§€ν›ˆμ΄κ°€ 갈 수 μžˆλŠ” 곳을 μ²΄ν¬ν•˜λŠ” 것이닀.




image

λ§Œμ•½ λ°˜λŒ€λ‘œ ν–ˆλ‹€λ©΄ μ§€ν›ˆμ΄κ°€ κ°”λ˜ 길에 뢈이 κ·Έ μ‹œκ°„μ— νΌμ Έλ²„λ €μ„œ μ§€ν›ˆμ΄κ°€ μž¬κ°€ λ˜μ–΄λ²„λ¦΄ μˆ˜λ„ 있음...!

μœ„ λ””ν…ŒμΌλ§Œ 신경써주면 μ†μ‰½κ²Œ ν•΄κ²° ν•  수 μžˆλ‹€!

πŸ“š μƒˆλ‘­κ²Œ μ•Œκ²Œλœ λ‚΄μš©

Copy link
Collaborator

@H0ngJu H0ngJu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'이 쯀이면 톡과닀' 만 μ—¬λŸ¬λ²ˆ μ™Έμ³€λ„€μš” γ…‹γ…‹...

  1. λΆˆμ΄λž‘ μ§€ν›ˆμ΄ qλ₯Ό λ™μ‹œμ— λŒλ €μ•Ό 함
  2. qλ₯Ό 돌릴 λ•Œ, 이번 ν„΄μ˜ λ°μ΄ν„°λ§Œ λ”°λ‘œ 관리해주어야 함
  3. 뢈이 μ—¬λŸ¬ 개일 수 있음 << 와 이건 κ²Œμ‹œνŒ 보고 μ°Ύμ•˜μŠ΅γ„΄λ””γ…... 11%μ—μ„œ μ•ˆ λ„˜μ–΄κ°€λ”λΌκ³ μš”,.....

λΆ„λͺ… BFS인데 λ‚―μ„€κ²Œ λŠκ»΄μ§€λŠ” λ¬Έμ œμ˜€λ„€μš”!! μˆ˜κ³ ν•˜μ…¨μŠ΅λ‹ˆλ‹€.

import sys
from collections import deque

def input() : return sys.stdin.readline().rstrip()

R, C = map(int, input().split())
maze = [list(input()) for _ in range(R)]
fx, fy = 0,0
jx, jy = 0,0
time = 1

dir = [(0,1), (0,-1), (1,0), (-1,0)]

# # λ²½ . κΈΈ J μ§€ν›ˆμ΄ F 뢈

j_q = deque() # 전체 경둜
f_q = deque()

for r in range(R):
    for c in range(C):
        if maze[r][c] == "J":
            j_q.append((r,c))
        if maze[r][c] == "F":
            f_q.append((r,c))
success = 0

while j_q:
    f_next = deque()

    while f_q:
        # 이번 ν„΄μ˜ 뢈만 λ²ˆμ§€λ„λ‘ 해야함
        fx, fy = f_q.popleft()

        for dx, dy in dir:
            if 0 <= fx+dx < R and 0 <= fy+dy < C and maze[fx+dx][fy+dy] == '.':
                maze[fx+dx][fy+dy] = "F"
                f_next.append((fx+dx,fy+dy))
    f_q = f_next

    j_next = deque()

    while j_q:
        # 이번 ν„΄μ˜ μ§€ν›ˆμ΄λ§Œ ν™•μΈν•˜λ©΄ 됨
        jx, jy = j_q.popleft()

        for dx, dy in dir:
            if not (0 <= jx+dx < R and 0 <= jy+dy < C):
                    print(time)
                    success = 1
                    break
            else:
                if maze[jx+dx][jy+dy] == '.':
                    maze[jx+dx][jy+dy] = "J"
                    j_next.append((jx+dx,jy+dy))
        if success: break

    j_q = j_next

    time += 1
    if success: break

if not success:
    print("IMPOSSIBLE")

fire = []

## λ³΄λ“œλ₯Ό λ§Œλ“œλŠ”λ°, κ°€μž₯자리λ₯Ό 도착 지점(*)으둜 감싼닀.
board = [["*" for _ in range(C+2)]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν˜Ήμ‹œ μš”λΆ€λΆ„ κ·Έλƒ₯ λ³΄λ“œ λ²”μœ„λ₯Ό λ²—μ–΄λ‚˜λ„ (r,cκ°€ 0미만, R,C 초과인 경우) 미둜 νƒˆμΆœν–ˆλ‹€λŠ”κ±Έ μ•Œ 수 μžˆμ„ 것 같은데 감싼 μ΄μœ κ°€ μžˆλ‚˜μš”??

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν˜Ήμ‹œ μš”λΆ€λΆ„ κ·Έλƒ₯ λ³΄λ“œ λ²”μœ„λ₯Ό λ²—μ–΄λ‚˜λ„ (r,cκ°€ 0미만, R,C 초과인 경우) 미둜 νƒˆμΆœν–ˆλ‹€λŠ”κ±Έ μ•Œ 수 μžˆμ„ 것 같은데 감싼 μ΄μœ κ°€ μžˆλ‚˜μš”??

ν—‰ κ·Έλƒ₯ 더 νŽΈν•˜κ²Œ κ°œλ°œν•˜λ €κ³  κ·Έλž¬μŠ΅λ‹ˆλ‹€!!!!!!

λΆ„κΈ°μ²˜λ¦¬ν•΄μ€˜μ•Ό ν•  것 κ°™μ•„μ„œ ...

@tgyuuAn tgyuuAn merged commit d39d389 into main Jan 8, 2025
11 checks passed
@tgyuuAn tgyuuAn deleted the 84-tgyuuAn branch January 8, 2025 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tgyuuAn ν•œ μ€„λ‘œλŠ” μ†Œκ°œν•  수 μ—†λŠ” λ‚¨μž. 리뷰 μ™„λ£Œ βœ”οΈ
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants