ENG  RUSTimus Online Judge
Online Judge
Online contests
About Online Judge
Frequently asked questions
Site news
Problem set
Submit solution
Judge status
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests

How to write Kotlin solutions

Kotlin programs are compiled on the server by the Kotlin command line compiler 1.9.22. The compiler is invoked with the following parameters:

kotlinc Main.kt -jvm-target 1.8

Solutions are executed by the Java 8 interpreter:

java -client -Xmx544m -Xss64m -DONLINE_JUDGE
    -classpath .;kotlin-stdlib.jar;kotlin-reflect.jar MainKt

You can find the compiler here.


package declaration is not supported.

Examples of solving a problem

A sample solution for 1000. A + B problem in Kotlin:

fun main(args: Array<String>) {
   val (x, y) = readLine()!!.split(' ').map(String::toInt)
   println(x + y)

Or even shorter:

fun main(args: Array<String>) =
   print(readLine()!!.split(' ').map(String::toInt).sum())

A sample solution for 1001. Reverse Root in Kotlin:

fun main(args: Array<String>) {
   val nums = mutableListOf<Double>()
   while (true) {
      nums +=
         (readLine() ?: break)
            .split(' ')
            .filter { !it.isEmpty() }
            .map { it.toDouble() }
       .forEach { println(Math.sqrt(it)) }

Or once again in a single operator:

fun main(args: Array<String>) =
   generateSequence { readLine() }
      .takeWhile { true }
      .map { a -> a.split(' ').filter(String::isNotEmpty).toMutableList() }
      .fold(mutableListOf<String>(), { a, b -> (a + b).toMutableList() })
      .map { x -> Math.sqrt(x) }

Earlier compilers

  • Kotlin 1.1.4 was used until September, 1 2020.
  • Kotlin 1.4.0 was used until January, 22 2024.