-
Notifications
You must be signed in to change notification settings - Fork 0
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
[장희직] - N번째 큰 수, 종이의 개수, 택배 배달과 수거하기, 222-폴링 #213
Conversation
val n = readln().toInt() | ||
val numbers = PriorityQueue<Number>(compareByDescending { it.value }) | ||
val board = MutableList(n) { MutableList(n) { 0L } } | ||
|
||
repeat(n) { x -> | ||
readln().split(' ').map { it.toLong() }.forEachIndexed { y, l -> | ||
board[x][y] = l | ||
if (x == n - 1) { | ||
numbers.add(Number(x, y, l)) | ||
} | ||
} | ||
} |
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.
이렇게 pq에 마지막 숫자들만 넣어주면 더 간편하네요!!
for (i in n - 1 downTo 0) { | ||
var visit = 0 | ||
while (saveDelivery < deliveries[i] || savePickup < pickups[i]) { | ||
visit++ | ||
saveDelivery += cap | ||
savePickup += cap | ||
} | ||
|
||
saveDelivery -= deliveries[i] | ||
savePickup -= pickups[i] | ||
|
||
distance += 2 * visit * (i + 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.
상상도 못한 로직이네요... 👍
val newFlattenCutList = mutableListOf<Int>() | ||
for (i in x until x + offset) { | ||
val fromIdx = (i * rowCnt) + y | ||
newFlattenCutList += flattenCutList.subList(fromIndex = fromIdx, toIndex = fromIdx + offset) |
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.
flatten해서 푸신 방법이 독특했습니다!
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.
고생하셨습니다!
newBoard.add(row) | ||
} | ||
|
||
polling(newBoard, width / 2, height / 2) |
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.
재귀로 만들 생각은 못했네요!!
val max = numbers.poll() | ||
numbers.add(Number(max.x - 1, max.y, board[max.x - 1][max.y])) |
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.
효율적인 아이디어..!💡
|
||
fun solve() { | ||
input() | ||
cutAndCheck(flattenCutList = paper.flatten(), rowCnt = n) |
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.
저도 flatten을 애용해봐야겠군요
📌 from issue #210 📌
📋문제 목록📋
📍추가로 해결한 문제📍