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

Envío 5451

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

  • Autor: bryancalisto
  • Fecha: 2021-12-17 19:50:18 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.007 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 27, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, 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.01 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 27, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, 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.03 s 4 KBi
#4
Incorrecto
0.007 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 27, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, 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.178 s 5 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 27, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, 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.669 s 5 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 27, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, 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.97 s 5 KBi
#8
Tiempo límite excedido
1.509 s 7 KBi
#9
Tiempo límite excedido
1.572 s 3 KBi
#10
Tiempo límite excedido
1.555 s 3 KBi
#11
Tiempo límite excedido
1.601 s 3 KBi
#12
Tiempo límite excedido
1.548 s 3 KBi
#13
Incorrecto
0.606 s 3 KBi
#14
Tiempo límite excedido
1.573 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 27, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, in contar
    conteo += contar(cantidad - moned, monedas, mem)
  File "script.py", line 18, 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
Puntos totales: 0 / 100

Código

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


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

    conteo = 0

    if cantidad == 0:
        return 1

    for moned in monedas:
        # if moned <= cantidad and moned not in mem:
        if moned <= cantidad:
            conteo += contar(cantidad - moned, monedas, mem)
            mem[cantidad] = conteo
    print('---')

    return conteo


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