Skip to content
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

Merged
merged 14 commits into from
Oct 24, 2022

Conversation

bngsh
Copy link
Contributor

@bngsh bngsh commented Oct 17, 2022

#12

💎 문제 해결

: ⭕️
랜선 자르기: ⭕️
크로스워드: ⭕️
단풍잎 이야기: 🔺
도피: 🔺

@bngsh bngsh self-assigned this Oct 17, 2022
@bngsh bngsh linked an issue Oct 17, 2022 that may be closed by this pull request
Copy link
Member

@gongdongho12 gongdongho12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

늦었긴 했지만 코드리뷰 완료!
확실히 지난번 언급드렸던건 반영하려는 모습이 👍🏼

Comment on lines +48 to +52
.fold(0) { acc, v ->
useList.add(v.toInt())
acc + getBit(v.toInt())
}
.let { games.add(it) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

목록 추가와 합을 합쳤군요 👍🏼
다만 sumOf 사용해도 동일했을것 같아요

Copy link
Member

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 }) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이부분도 maxOf 사용해도 좋았을것 같아요

Comment on lines +21 to +22
var dp = Array(0) { LongArray(0) }
var moves = Array(0) { LongArray(0) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

초기화가 별도로 이루어지는데 lateinit 했어도 좋았을것 같아요

Comment on lines +29 to +33
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]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sumOf 썼으면 var 선언없이 사용 가능했을것 같아요

Comment on lines +66 to +67
if (ans == ONEPROB) println("1." + "0".repeat(18))
else println(String.format("0.%18d", ans))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

%.18d 로 ans 출력하면 조건식 없어도 될것 같아요

Comment on lines +22 to +24
fun flatIdx() : Int {
return r * 4 + c
}
Copy link
Member

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

words가 var 일 이유가 있나요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정렬을 우선순위 Queue로 대체했네요 👍🏼

Comment on lines +28 to +38
(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)
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"#"은 전역변수로 BLANK 라는 변수로 지정하면 좋을것 같아요

Copy link
Member

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)
}

이부분 확장함수로 뺴두면 최적화 할 수 있을것 같아요

Comment on lines +67 to +75
if (kingPos + move == stonePos) {
if ((stonePos + move).isInside()) {
kingPos = stonePos
stonePos += move
}
}
else if ((kingPos + move).isInside()) {
kingPos += move
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newKingPos나 newStonePos를 미리 만들어뒀으면 plus operator를 두번씩 연산하는 일을 줄일 수 있징 않을까요?

Comment on lines +15 to +17
fun Char.toIdx() : Int {
return if (this.isDigit()) (digitToInt() - 1) else code - 'A'.code
}
Copy link
Member

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 값까지 한번에 받을 수 있게 해도 좋지 않았을까요?

@gongdongho12 gongdongho12 added the review complete 리뷰 완료 label Oct 23, 2022
@bngsh bngsh merged commit df8c2e3 into main Oct 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review complete 리뷰 완료
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3주차 문제]
2 participants