제출 #886036

#제출 시각아이디문제언어결과실행 시간메모리
886036CDuongSum Zero (RMI20_sumzero)Kotlin (JVM)
0 / 100
478 ms32336 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(10) { 1 } while (i < 10) { cope[i] = cope[i - 1] * 4 i++ } var nxt = Array(10) { 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 < 10) { j = 0 while (j < n) { nxt[i][j] = 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 = 9 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++ // } }

컴파일 시 표준 에러 (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...