-
Notifications
You must be signed in to change notification settings - Fork 5
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
25-LJEDD2 #98
Conversation
흠 저는 엉뚱한 데서 해멨네요... 항상 row, col 값을 꺼내는 파트에서 큐 반복문 break 조건을 걸었었는데, 이 문제는 nrow, ncol 값을 꺼낼 때 검사하는 게 더 합리적이네요... 제 경우 아예 바깥 반복문을 tick이란 일종의 시간 카운팅 느낌의 반복문으로 설정해서 tick 값을 이용해 원본 줄 정보를 해당 시간마다 무너지도록 설정했습니다. from collections import deque
input = open(0).readline
N, k = map(int, input().split())
lines = [list(map(int, input().rstrip())) for _ in range(2)]
def out_of_bound(c) -> bool:
return not (0 <= c < N)
def bfs() -> bool:
q = deque([(0, 0)])
for tick in range(0, N):
for _ in range(len(q)):
r, c = q.popleft()
lines[0][tick] = 0 # 다음 칸으로 갈 꺼니까
lines[1][tick] = 0 # 이 시간 부로 현재 칸은 무너진다
for nr, nc in ((r, c + 1), (r, c - 1), (r ^ 1, c + k)):
if nc >= N:
return True
if out_of_bound(nc) or lines[nr][nc] == 0:
continue
lines[nr][nc] = 0
q.append((nr, nc))
return False
print(1 if bfs() else 0) |
와 ! 외쳐 갓교황 ! |
# if col >= n-1 or col + k >= n: | ||
# return True | ||
|
||
for nrow, ncol in ((row, col+1),(row, col-1),(~row, col+k)): # ~ 사용하면 0과 1 스위칭가능 |
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.
비트연산자로 스위칭하는 !!!! 아이디어 좋습니다🤔🤔🤔👍
사실 비트연산자라는게 있다~ 라고만 들었지 실제로 사용한 적은 한번도 없었는데요,
정은님의 코드에서 0과 1을 스위치할 때 사용하는 걸 보고 다음에 저도 이런 경우가 생긴다면 꼭꼭꼮 활용해보겠습니다!!
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.
예린님이 말씀하셨던 비트 연산자를 활용하는 아이디어가 저도 인상깊었습니다!
저도 다음에 0과 1을 스위칭하는 경우가 생기면 꼭꼭 활용해보도록 하죠😎
visited = [[0] * n for _ in range(2)] | ||
|
||
def OOB(y,time): | ||
return not(time < y < n) # 그냥 time도 포함해서 접근 가능 범위를 제한해주면 되지 않을까? |
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.
오옷 이 아이디어는 생각해본 적이 없는데 매번 범위 조건이 바뀌도록 반환하는 방법이 있었군요!
다음에 함수를 작성할 때 비슷한 상황이 생기면 이렇게 써보도록 하겠습니닷
# if col >= n-1 or col + k >= n: | ||
# return True | ||
|
||
for nrow, ncol in ((row, col+1),(row, col-1),(~row, col+k)): # ~ 사용하면 0과 1 스위칭가능 |
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.
dfs에서 상하좌우할 때도 이런 방식으로 했었던 것 같은데 요번에 비트연산자를 활용해서 해주니 또 처음보는 것 같네요 😂 이번 기회로 다시 머리에 새기고 갑니다 ☺︎☻
🔗 문제 링크
백준 - 그래프 탐색 | 점프 게임
문제 설명
제한 조건
✔️ 소요된 시간
2시간
✨ 수도 코드
1. 문제 지문 이해하기
2. 문제 설명 따라 구현하기
2.-1 시간에 따라 좁아지는 맵
time < col < N
으로 매번 범위 조건이 바뀌도록 구현하였다.2-2. 3가지의 이동 방법
~
를 사용해서 원래 데이터의 반대되는 데이터로 바꿔줄 수 있다.3. 최종 코드
📚 새롭게 알게된 내용