█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 4125

Problema 0x25 - Suma de un subarreglo grande

  • Autor: williamzborja
  • Fecha: 2021-05-17 19:16:16 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.003 s 52 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 2
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
main.loadSums(0xc000096030, 0x1, 0x1, 0xc000096038, 0x1, 0x1, 0xa)
	/box/main.go:23 +0x69
main.main()
	/box/main.go:56 +0x34e
0.005 s 8 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 2
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
main.loadSums(0xc0000a2040, 0x1, 0x1, 0xc0000a2048, 0x1, 0x1, 0xa)
	/box/main.go:23 +0x69
main.main()
	/box/main.go:56 +0x34e
0.006 s 10 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 2
panic: runtime error: index out of range [5] with length 5

goroutine 1 [running]:
main.loadSums(0xc000018060, 0x5, 0x5, 0xc000018090, 0x5, 0x5, 0xa)
	/box/main.go:23 +0x69
main.main()
	/box/main.go:56 +0x34e
0.005 s 52 KBi
#5
Correcto
0.005 s 49 KBi
#6
Correcto
0.009 s 45 KBi
#7
Correcto
0.007 s 53 KBi
#8
Correcto
0.34 s 13 KBi
#9
Tiempo límite excedido
1.045 s 10 KBi
#10
Tiempo límite excedido
1.054 s 9 KBi
#11
Tiempo límite excedido
1.065 s 9 KBi
#12
Tiempo límite excedido
1.099 s 14 KBi
#13
Tiempo límite excedido
1.051 s 11 KBi
#14
Tiempo límite excedido
1.049 s 16 KBi
Puntos totales: 36 / 100

Código

package main

import (
	"fmt"
)

func solve(a []int, sums []int, p, q int) {
	if p == 0 {
		fmt.Println(sums[q])
		return
	}

	if p-q == 0 {
		fmt.Println(a[q])
		return
	}
	fmt.Println(sums[q] - sums[p-1])
}

func loadSums(a []int, sums []int, n int) {
	sum := 0
	for i := 0; i < n; i++ {
		sum += a[i]
		sums[i] = sum
	}
}

func main() {
	var n int
	var p, q int

	_, err := fmt.Scanf("%d", &n)
	if err != nil {
		panic(err)
	}
	a := make([]int, n)
	sums := make([]int, n)
	for i := 0; i < n; i++ {
		_, err := fmt.Scanf("%d", &a[i])
		if err != nil {
			panic(err)
		}
	}

	_, err = fmt.Scanf("%d", &n)
	if err != nil {
		panic(err)
	}

	for i := 0; i < n; i++ {

		_, err := fmt.Scanf("%d %d", &p, &q)
		if err != nil {
			panic(err)
		}
		loadSums(a, sums, n)
		solve(a, sums, p, q)
	}
}