You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2차원 배열에 수가 있고 써있는 수만큼의 시간이 지나야 다음 노드로 이동할 수 있다. n-1, n-1에 도착 가능한 최소 시간을 구하는 문제.
Solution
단순 완전 탐색 BFS로 하니 시간 안에 통과는 되지만 매우 느리다.
좀 더 생각을 해보면 시간은 최소 0, 최대 n^2 이므로 이분 탐색으로 가능한 최소 시간을 구한다면 n^2 log(n^2) 으로 구할 수 있다. 다른 방법으로 우선순위 큐를 쓰면 가장 작은 시간부터 탐색을 해나갈 수 있고 이렇게도 n^2 log(n^2) 으로 가능하다.
This discussion was converted from issue #44 on September 15, 2026 11:02.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem link
https://leetcode.com/problems/swim-in-rising-water/
Problem Summary
2차원 배열에 수가 있고 써있는 수만큼의 시간이 지나야 다음 노드로 이동할 수 있다. n-1, n-1에 도착 가능한 최소 시간을 구하는 문제.
Solution
단순 완전 탐색 BFS로 하니 시간 안에 통과는 되지만 매우 느리다.
좀 더 생각을 해보면 시간은 최소 0, 최대 n^2 이므로 이분 탐색으로 가능한 최소 시간을 구한다면 n^2 log(n^2) 으로 구할 수 있다. 다른 방법으로 우선순위 큐를 쓰면 가장 작은 시간부터 탐색을 해나갈 수 있고 이렇게도 n^2 log(n^2) 으로 가능하다.
Source Code
Brute Force BFS (4304 ms)
Priority Queue BFS (146 ms)
All reactions