시배's Android
Algorithm | 백준 Kotlin 5548 행성 탐사 본문
5549번: 행성 탐사
상근이는 우주선을 타고 인간이 거주할 수 있는 행성을 찾고 있다. 마침내, 전 세계 최초로 인간이 거주할 수 있는 행성을 찾았다. 이 행성은 정글, 바다, 얼음이 뒤얽힌 행성이다. 상근이는 이
www.acmicpc.net
private fun main() {
val sb = StringBuilder()
val (n, m) = readLine()!!.split(" ").map{it.toInt()}
val k = readLine()!!.toInt()
val board = (1 .. n).map { readLine()!!.toList() }
val prefixed = MutableList(n + 1) { MutableList(m + 1) { MutableList(3) { 0 } } }
for (i in 1 .. n) {
for (j in 1 .. m) {
for (l in 0 until 3) prefixed[i][j][l] = prefixed[i - 1][j][l] + prefixed[i][j - 1][l] - prefixed[i - 1][j - 1][l]
when (board[i - 1][j - 1]) {
'J' -> prefixed[i][j][0] ++
'O' -> prefixed[i][j][1] ++
'I' -> prefixed[i][j][2] ++
}
}
}
repeat(k) {
val (x1, y1, x2, y2) = readLine()!!.split(" ").map{it.toInt()}
sb.append("${prefixed[x2][y2][0] - prefixed[x1 - 1][y2][0] - prefixed[x2][y1 - 1][0] + prefixed[x1 - 1][y1 - 1][0]} ${prefixed[x2][y2][1] - prefixed[x1 - 1][y2][1] - prefixed[x2][y1 - 1][1] + prefixed[x1 - 1][y1 - 1][1]} ${prefixed[x2][y2][2] - prefixed[x1 - 1][y2][2] - prefixed[x2][y1 - 1][2] + prefixed[x1 - 1][y1 - 1][2]}\n")
}
println(sb)
}
'Algorithm' 카테고리의 다른 글
Algorithm | 백준 Kotlin 2606 바이러스 (0) | 2023.10.07 |
---|---|
Algorithm | 백준 Kotlin 12101 1,2,3 더하기 2 (0) | 2023.10.07 |
Algorithm | 백준 Kotlin 3273 두 수의 합 (0) | 2023.10.07 |
Algorithm | 백준 Kotlin 6443 애너그램 (0) | 2023.09.23 |
Algorithm | 백준 Kotlin 2553 마지막 팩토리얼 수 (0) | 2023.09.23 |