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

Envío 5453

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

  • Autor: bryancalisto
  • Fecha: 2021-12-17 20:04:28 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.01 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 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.02 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 = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [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
#4
Correcto
0.011 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 26, in <module>
    print(contar(m, monedas, {}))
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.12 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 = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.364 s 3 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 = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.414 s 3 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 = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.276 s 4 KBi
#9
Tiempo límite excedido
1.6 s 3 KBi
#10
Tiempo límite excedido
1.554 s 3 KBi
#11
Tiempo límite excedido
1.6 s 3 KBi
#12
Tiempo límite excedido
1.568 s 3 KBi
#13
Correcto
0.18 s 3 KBi
#14
Tiempo límite excedido
1.551 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 = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  File "script.py", line 17, in contar
    conteo = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007
  [Previous line repeated 995 more times]
  File "script.py", line 12, in contar
    if cantidad == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.009 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 = (conteo + contar(cantidad - moned, monedas, mem)) % 1000000007

    mem[cantidad] = conteo

    return conteo


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