update sungkohan
This commit is contained in:
39
storage/sungkohan/kt/completed/2025-div2-A.kt
Normal file
39
storage/sungkohan/kt/completed/2025-div2-A.kt
Normal file
@@ -0,0 +1,39 @@
|
||||
import java.io.StreamTokenizer
|
||||
|
||||
fun rectanglePermCount(n: Int, table: Array<Array<Int>>): Int {
|
||||
var cnt = 0
|
||||
for (r1 in 0 until n) {
|
||||
for (c1 in 0 until n) {
|
||||
for (r2 in r1 until n) {
|
||||
for (c2 in c1 until n) {
|
||||
val list: MutableList<Int> = mutableListOf()
|
||||
for (i in r1..r2) {
|
||||
for (j in c1..c2) {
|
||||
list.add(table[i][j])
|
||||
}
|
||||
}
|
||||
list.sort()
|
||||
if (list.withIndex().all { it.index + 1 == it.value }) {
|
||||
cnt++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return cnt
|
||||
}
|
||||
|
||||
fun main() = with(StreamTokenizer(System.`in`.bufferedReader())) {
|
||||
nextToken()
|
||||
val n = nval.toInt()
|
||||
|
||||
val table = Array(n) { Array(n) { 0 } }
|
||||
for (i in 0 until n) {
|
||||
for (j in 0 until n) {
|
||||
nextToken()
|
||||
table[i][j] = nval.toInt()
|
||||
}
|
||||
}
|
||||
|
||||
println(rectanglePermCount(n, table))
|
||||
}
|
||||
Reference in New Issue
Block a user