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

Envío 5452

Problema 0xcb - Contar maneras de formar una cantidad con monedas

  • Autor: bryancalisto
  • Fecha: 2021-12-17 20:02:12 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.033 s 6 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.008 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.012 s 3 KBi
#4
Correcto
0.036 s 7 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.327 s 4 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.138 s 4 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.397 s 4 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.811 s 4 KBi
#9
Tiempo límite excedido
1.574 s 3 KBi
#10
Tiempo límite excedido
1.581 s 3 KBi
#11
Tiempo límite excedido
1.586 s 3 KBi
#12
Tiempo límite excedido
1.516 s 3 KBi
#13
Correcto
0.515 s 3 KBi
#14
Tiempo límite excedido
1.6 s 3 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 17, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.028 s 3 KBi
Puntos totales: 14 / 100

Código

N = input()
monedas = list(map(int, input().split(' ')))
M = int(input())


def contar(cantidad, monedas, mem):
    if cantidad in mem:
        return mem[cantidad]

    conteo = 0

    if cantidad == 0:
        return 1

    for moned in monedas:
        if moned <= cantidad and moned not in mem:
            conteo += contar(cantidad - moned, monedas, mem)

    mem[cantidad] = conteo

    return conteo


for i in range(M):
    m = int(input())
    print(contar(m, monedas, {}))