문제링크
import java.io.BufferedReader
import java.io.BufferedWriter
private lateinit var bufferedReader: BufferedReader
private lateinit var bufferedWriter: BufferedWriter
private lateinit var papers: MutableList<List<Int>>
private lateinit var answer: Array<Int>
fun main() {
bufferedReader = System.`in`.bufferedReader()
bufferedWriter = System.out.bufferedWriter()
val n = bufferedReader.readLine().toInt()
papers = mutableListOf()
repeat(n) {
val paper = bufferedReader
.readLine()
.split(" ")
.map { it.toInt() }
papers.add(paper)
}
answer = Array(2) { 0 }
checkColor(n, 0, 0)
bufferedWriter.write("${answer[0]}\n")
bufferedWriter.write("${answer[1]}\n")
bufferedReader.close()
bufferedWriter.close()
}
fun checkColor(n: Int, startX: Int, startY: Int) {
val color = papers[startX][startY]
if (n == 1) {
answer[color]++
return
}
for (i in startX until startX + n) {
for (j in startY until startY + n) {
if (papers[i][j] != color) {
checkColor(n / 2, startX, startY)
checkColor(n / 2, startX + n / 2, startY)
checkColor(n / 2, startX, startY + n / 2)
checkColor(n / 2, startX + n / 2, startY + n / 2)
return
}
}
}
answer[color]++
}