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

Envío 3819

Problema 0x25 - Suma de un subarreglo grande

  • Autor: bryancalisto
  • Fecha: 2021-04-17 14:04:51 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.004 s 4 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.005 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.004 s 10 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.002 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.002 s 5 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.005 s 5 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 134
a.out: malloc.c:2385: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)' failed.
run: line 1:     3 Aborted                 (core dumped) ./a.out
0.002 s 4 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.011 s 1 KBi
#9
Tiempo límite excedido
1.075 s 2 KBi
#10
Tiempo límite excedido
1.06 s 2 KBi
#11
Tiempo límite excedido
1.07 s 2 KBi
#12
Tiempo límite excedido
1.099 s 2 KBi
#13
Incorrecto
0.042 s 2 KBi
#14
Tiempo límite excedido
1.068 s 10 KBi
Puntos totales: 0 / 100

Código

#include<stdio.h>
#include<stdlib.h>

int sumarDesdeHasta(int *arr, int p, int q)
{
  int res = 0;
  // printf("p: %d / q: %d\n", p, q);
  for (int i = p; i <= q; i++)
  {
    // printf("%d + %d = %d\n", res, arr[i], res + arr[i]);
    res += arr[i];
  }

  return res;
}

int main()
{
  int N, c, i = 0, j, *arr, *consultas;

  scanf("%d*[^\n]", &N);

  arr = (int *)malloc(sizeof(int) * N);

  while (i < N && fscanf(stdin, "%d", &arr[i++]) == 1)
    ;

  scanf("%d*[^\n]", &c);

  consultas = (int *)malloc(sizeof(int) * c * 2);

  // leer cada consulta
  for (i = 0; i < c; i++)
  {
    j = 0;
    while (j < 2 && fscanf(stdin, "%d", &consultas[i + i * 2 + j++]) == 1)
      ;
  }

  // for (i = 0; i < c; i++) {
  //   printf("%d %d\n", consultas[i + i * 2], consultas[i + i * 2 + 1]);
  // }

  // Ejecutar cada consulta
  for (i = 0; i < c; i++)
  {
    printf("%d\n", sumarDesdeHasta(arr, consultas[i + i * 2], consultas[i + i * 2 + 1]));
    // printf("%d", consultas[i][j]);
  }

  return 0;
}