-
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
[소병희] - 내리막 길, 치즈, 가장 긴 증가하는 부분 수열 4, 삼각 달팽이 #270
Conversation
idx = j | ||
} | ||
} | ||
if (idx != i) dp[i].addAll(dp[idx]) |
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.
오 addAll 좋아요
var airContact = Array(n) { IntArray(m) } | ||
val q = ArrayDeque<IntArray>() | ||
var time = 0 | ||
var cheese = 0 |
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.
미리 치즈 개수를 세어놓는 것도 좋네요!!
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 (idx != i) dp[i].addAll(dp[idx]) | ||
dp[i].add(arr[i]) |
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.
오.. 요런식으로 하면 초기화 처리를 앞에 안해줘도 되는군요!
return visited[r][c] | ||
} | ||
|
||
println(dfs(0, 0)) |
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.
아 어차피 최종적으로 반환을 하는군요..
while(side > 0) { | ||
for(i in sl until sl + side) { | ||
triangle[i].add(round, count++) | ||
} | ||
|
||
repeat(side - 1) { i -> | ||
triangle[sl + side - 1].add(round + i + 1, count++) | ||
} | ||
|
||
for(i in sl + side-2 downTo sl + 1) { | ||
triangle[i].add(triangle[i].size - round, count++) | ||
} | ||
|
||
round++ | ||
side -= 3 | ||
sl += 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.
이거를 직접 구현하시다니...
sl += 2 | ||
} | ||
|
||
return triangle.flatMap { it.toList() }.toIntArray() |
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.
flatMap 배워갑니다!
for(i in 1 until n) { | ||
var idx = i | ||
for(j in i - 1 downTo 0) { | ||
if (dp[j].last() < arr[i] && dp[j].size > dp[idx].size) { | ||
idx = j | ||
} | ||
} |
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.
앞에서부터 탐색하는 게 가능할까 했는데 단순히 앞뒤 차이였군요,,
배열을 저장하는 것까지!
확실히 다른 풀이 보니깐 좋습니다!!👍
while(side > 0) { | ||
for(i in sl until sl + side) { | ||
triangle[i].add(round, count++) | ||
} | ||
|
||
repeat(side - 1) { i -> | ||
triangle[sl + side - 1].add(round + i + 1, count++) | ||
} | ||
|
||
for(i in sl + side-2 downTo sl + 1) { | ||
triangle[i].add(triangle[i].size - round, count++) | ||
} | ||
|
||
round++ | ||
side -= 3 | ||
sl += 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.
오 중간에 넣어주는 것 시뮬레이션 생각하기 쉽지 않을 것 같은데,, 👍
fun checkAir() { | ||
airContact = Array(n) { IntArray(m) } | ||
airContact[0][0]++ | ||
q.add(intArrayOf(0, 0)) | ||
|
||
while(q.isNotEmpty()) { | ||
val (r, c) = q.removeFirst() | ||
for(d in 0 until 4) { | ||
val nr = r + dr[d] | ||
val nc = c + dc[d] | ||
if (nr !in 0 until n || nc !in 0 until m) continue | ||
if (paper[nr][nc] == 0 && airContact[nr][nc] > 0) continue | ||
|
||
airContact[nr][nc]++ | ||
if (paper[nr][nc] == 1) continue | ||
q.add(intArrayOf(nr, nc)) | ||
} | ||
} | ||
} |
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.
바깥의 공기들만 돌면서 치즈와 만나면 맞닿은 공기 개수까지 처리를 하는군요 👍🫡
📌 from issue #266 📌
📋문제 목록📋