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

Envío 4705

Problema 0x25 - Suma de un subarreglo grande

  • Autor: cams2692
  • Fecha: 2021-08-10 02:45:07 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 6 KBi
#2
Incorrecto
0.005 s 7 KBi
#3
Correcto
0.004 s 7 KBi
#4
Correcto
0.005 s 6 KBi
#5
Correcto
0.006 s 7 KBi
#6
Correcto
0.005 s 7 KBi
#7
Correcto
0.008 s 5 KBi
#8
Correcto
0.163 s 14 KBi
#9
Tiempo límite excedido
1.083 s 15 KBi
#10
Tiempo límite excedido
1.057 s 12 KBi
#11
Tiempo límite excedido
1.08 s 14 KBi
#12
Tiempo límite excedido
1.073 s 12 KBi
#13
Tiempo límite excedido
1.083 s 13 KBi
#14
Tiempo límite excedido
1.079 s 13 KBi
Puntos totales: 50 / 100

Código

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type SubArrayData struct {
	P int64
	Q int64
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	n, _ := reader.ReadString('\n')
	n = strings.ReplaceAll(n, "\n", "")
	nNumber, _ := strconv.ParseInt(n, 10, 64)
	nArray, _ := reader.ReadString('\n')
	nArray = strings.ReplaceAll(nArray, "\n", "")
	numbers := strings.Split(nArray, " ")
	c, _ := reader.ReadString('\n')
	c = strings.ReplaceAll(c, "\n", "")
	cNumber, _ := strconv.ParseInt(c, 10, 64)
	numbersCases := make([]SubArrayData, 0)
	numbersSolution := make([]int64, 0)
	var numberFirst int64 = nNumber - 1
	var numberLast int64 = 0
	for i := 0; i < int(cNumber); i++ {
		caseLine, _ := reader.ReadString('\n')
		caseLine = strings.ReplaceAll(caseLine, "\n", "")
		numbersCase := strings.Split(caseLine, " ")
		p, _ := strconv.ParseInt(numbersCase[0], 10, 64)
		q, _ := strconv.ParseInt(numbersCase[1], 10, 64)
		numbersCases = append(numbersCases, SubArrayData{P: p, Q: q})
		if p < numberFirst {
			numberFirst = p
		}
		if q > numberLast {
			numberLast = q
		}
		numbersSolution = append(numbersSolution, 0)
	}

	for numberFirst < numberLast {
		number, _ := strconv.ParseInt(numbers[numberFirst], 10, 64)
		number2, _ := strconv.ParseInt(numbers[numberLast], 10, 64)
		for j := 0; j < len(numbersCases); j++ {
			subArray := numbersCases[j]
			if numberFirst >= subArray.P && numberFirst <= subArray.Q {
				numbersSolution[j] = numbersSolution[j] + number
			}
			if numberLast >= subArray.P && numberLast <= subArray.Q && numberFirst < numberLast {
				numbersSolution[j] = numbersSolution[j] + number2
			}
		}
		numberFirst++
		numberLast--
	}

	for i := 0; i < len(numbersSolution); i++ {
		fmt.Println(numbersSolution[i])
	}

}