Submission #886039

#TimeUsernameProblemLanguageResultExecution timeMemory
886039CDuongSum Zero (RMI20_sumzero)Kotlin (JVM)
0 / 100
515 ms31984 KiB
import kotlin.math.* import java.util.Vector private fun readLn() = readLine()!! private fun readInt() = readLn().toInt() private fun readLong() = readLn().toLong() private fun readStrings() = readLn().split(" ") private fun readInts() = readStrings().map { it.toInt() } private fun readLongs() = readStrings().map { it.toLong() } fun main() { var n = readInt() var a = readInts() var i: Int = 0 i = 1 var cope = Array(9) { 1 } while (i < 9) { cope[i] = cope[i - 1] * 5 i++ } var nxt = Array(9) { Array<Int>(n + 2) { n + 1 } } var mp = mutableMapOf<Long, Int>() mp[0] = 0 i = 0 var cur_sum: Long = 0 while (i < n) { cur_sum += a[i] if (mp[cur_sum] != null) { // println(mp[cur_sum]) nxt[0][mp[cur_sum]!!] = i + 1 } mp[cur_sum] = i + 1; i++; } i = n; while (i >= 0) { nxt[0][i] = min(nxt[0][i], nxt[0][i + 1]) i-- } i = 1 var j = 0 while (i < 9) { j = 0 while (j < n) { nxt[i][j] = nxt[i - 1][nxt[i - 1][nxt[i - 1][nxt[i - 1][nxt[i - 1][j]]]]] // println("${i}, ${j}, ${nxt[i][j]}") j++ } i++; } var q = readInt() repeat(q) { var (l, r) = readInts() l-- var res = 0 i = 8 while (i >= 0 && l < n) { while (nxt[i][l] <= r) { res += cope[i] l = nxt[i][l] } i-- } println(res) } // i = 0 // while (i < n) { // println(nxt[0][i]) // i++ // } }

Compilation message (stderr)

sumzero.kt:14:18: warning: variable 'i' initializer is redundant
    var i: Int = 0
                 ^
sumzero.kt:47:13: warning: variable 'j' initializer is redundant
    var j = 0
            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...