Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Incorrecto
|
0.036 s | 7 KBi |
#2 |
Correcto
|
0.152 s | 32 KBi |
#3 |
Correcto
|
0.058 s | 7 KBi |
#4 |
Correcto
|
0.035 s | 7 KBi |
#5 |
Incorrecto
|
0.038 s | 7 KBi |
#6 |
Incorrecto
|
0.038 s | 7 KBi |
#7 |
Incorrecto
|
0.055 s | 7 KBi |
#8 |
Incorrecto
|
0.501 s | 18 KBi |
#9 |
Incorrecto
|
1.0 s | 37 KBi |
#10 |
Tiempo límite excedido
|
1.014 s | 39 KBi |
#11 |
Tiempo límite excedido
|
1.025 s | 38 KBi |
#12 |
Incorrecto
|
0.561 s | 39 KBi |
#13 |
Incorrecto
|
0.551 s | 37 KBi |
#14 |
Incorrecto
|
0.996 s | 37 KBi |
const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout }); let lineCounter = 0; let subTotalsArray; function sumSubTotals(initialArray) { let currentSum = 0 let sumsArray = [] for(let i = 0; i < initialArray.length; i++) { currentSum = initialArray[i] + currentSum; sumsArray.push(currentSum); } return sumsArray } const sumSubArray = (fromIndex, toIndex) => { if (fromIndex === 0) return subTotalsArray[toIndex] return subTotalsArray[toIndex] - subTotalsArray[fromIndex - 1]; } const getInitialArrayFromInput = input => { const initialValues = input.split(""); const initialArray = []; for (value of initialValues) { initialArray.push(Number(value)) } return initialArray } rl.on("line", (line) => { ++lineCounter; if (lineCounter === 2) { // Run the initial algorithm const initialArray = getInitialArrayFromInput(line); subTotalsArray = sumSubTotals(initialArray) } if (lineCounter > 3) { // these are the inputs Q & P const [Q, P] = line.split(" ").map(Number); console.log(sumSubArray(Q, P)) } })