-
-
Save omo/060530ae0f1aafe95b3a63387de33ab7 to your computer and use it in GitHub Desktop.
Copying the Solution for https://codeforces.com/problemset/problem/1713/C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.* | |
fun debugln(str: String) = println(str) | |
//fun debugln(@Suppress("UNUSED_PARAMETER") unused: String) = {} | |
fun search(n: Int) : List<Int> { | |
val ans = (0 until n).toMutableList() | |
fun fill(r: Int) { | |
if (r < 0) { | |
return | |
} | |
// The sqrt that should exist. | |
val s = sqrt(2.0 * r).toInt().let { it * it } | |
assert(r < s && s < 2 * r) | |
// ??? Why is this range? | |
val l = s - r | |
(l .. r).forEach { ans[it] = s - it } | |
// Recurse down to the remaining range. | |
fill(l - 1) | |
debugln("$l to $r is filled with $s") | |
} | |
fill(n - 1) | |
return ans | |
} | |
fun main() { | |
repeat(readLine()!!.toInt()) { | |
val len = readLine()!!.toInt() | |
println(search(len).joinToString(separator=" ")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment