-
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
[Week3] 소병희: 킹, 랜선 자르기, 크로스워드 #15
Conversation
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.
늦었긴 했지만 코드리뷰 완료!
확실히 지난번 언급드렸던건 반영하려는 모습이 👍🏼
.fold(0) { acc, v -> | ||
useList.add(v.toInt()) | ||
acc + getBit(v.toInt()) | ||
} | ||
.let { games.add(it) } |
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.
목록 추가와 합을 합쳤군요 👍🏼
다만 sumOf 사용해도 동일했을것 같아요
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.
이렇게 반복하는 상황이 있을때 합과 배열의 추가가 있자나요
값을 합하는 것 보다 배열에 add 하는 것이 mutableList = ArrayList라 연산시에 배열을 추가로 생성하는 부분이 있어 더 무거운데 배열을 map 해서 만들고 값 합은 내부에서 하는게 효율적일것 같아요!
|
||
dfs(0, 0) | ||
|
||
pickList.forEach { bm -> answer = Integer.max(answer, games.count { it and bm == it }) } |
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.
이부분도 maxOf 사용해도 좋았을것 같아요
var dp = Array(0) { LongArray(0) } | ||
var moves = Array(0) { LongArray(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.
초기화가 별도로 이루어지는데 lateinit 했어도 좋았을것 같아요
var prob = 0L | ||
for(from in 0 until n) { | ||
if(dp[day-1][from] < 0) getDp(day-1, from) | ||
prob += dp[day-1][from] * moves[from][dst] | ||
} |
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.
sumOf 썼으면 var 선언없이 사용 가능했을것 같아요
if (ans == ONEPROB) println("1." + "0".repeat(18)) | ||
else println(String.format("0.%18d", ans)) |
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.
%.18d 로 ans 출력하면 조건식 없어도 될것 같아요
fun flatIdx() : Int { | ||
return r * 4 + c | ||
} |
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.
객체 내부 함수 자주 사용하는 만큼 👍🏼
class Solution { | ||
val br = BufferedReader(InputStreamReader(System.`in`)) | ||
|
||
var words = PriorityQueue<String> { a, b -> when { |
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.
words가 var 일 이유가 있나요?
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.
정렬을 우선순위 Queue로 대체했네요 👍🏼
(0 until row).forEach { r -> | ||
puzzles[r].split("#").filter{ it.length > 1 }.let { | ||
words.addAll(it) | ||
} | ||
} | ||
|
||
(0 until col).forEach { c -> | ||
puzzles.map{ it[c] }.joinToString("").split("#").filter{ it.length > 1 }.let { | ||
words.addAll(it) | ||
} | ||
} |
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.
"#"은 전역변수로 BLANK 라는 변수로 지정하면 좋을것 같아요
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.
사실 중복되는 부분이 좀 보이는데
.filter{ it.length > 1 }.let {
words.addAll(it)
}
이부분 확장함수로 뺴두면 최적화 할 수 있을것 같아요
if (kingPos + move == stonePos) { | ||
if ((stonePos + move).isInside()) { | ||
kingPos = stonePos | ||
stonePos += move | ||
} | ||
} | ||
else if ((kingPos + move).isInside()) { | ||
kingPos += move | ||
} |
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.
newKingPos나 newStonePos를 미리 만들어뒀으면 plus operator를 두번씩 연산하는 일을 줄일 수 있징 않을까요?
fun Char.toIdx() : Int { | ||
return if (this.isDigit()) (digitToInt() - 1) else code - 'A'.code | ||
} |
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.
이 함수가 Char가 아니라 String.toIdx(i: Int): Int 형식으로 아래에 사용하는 배열에서 0, 1 값까지 한번에 받을 수 있게 해도 좋지 않았을까요?
#12
💎 문제 해결
킹: ⭕️
랜선 자르기: ⭕️
크로스워드: ⭕️
단풍잎 이야기: 🔺
도피: 🔺