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

Envío 6560

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

  • Autor: bryancalisto
  • Fecha: 2022-08-06 01:19:22 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.014 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 33, in <module>
    print(contar(valor, monedas))
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  [Previous line repeated 995 more times]
  File "script.py", line 7, in contar
    if valor == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.019 s 4 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 33, in <module>
    print(contar(valor, monedas))
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  [Previous line repeated 995 more times]
  File "script.py", line 7, in contar
    if valor == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.022 s 5 KBi
#4
Correcto
0.013 s 3 KBi
#5
Correcto
0.06 s 3 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 120
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [Errno 27] File too large
0.278 s 12 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 120
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [Errno 27] File too large
0.395 s 13 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 120
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [Errno 27] File too large
0.193 s 11 KBi
#9
Correcto
0.718 s 4 KBi
#10
Tiempo límite excedido
1.59 s 10 KBi
#11
Tiempo límite excedido
1.557 s 10 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 120
Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>
OSError: [Errno 27] File too large
0.939 s 10 KBi
#13
Correcto
0.713 s 4 KBi
#14
Tiempo límite excedido
1.572 s 12 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 33, in <module>
    print(contar(valor, monedas))
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  File "script.py", line 19, in contar
    combs += contar(valor - moned, monedas)
  [Previous line repeated 995 more times]
  File "script.py", line 7, in contar
    if valor == 0:
RecursionError: maximum recursion depth exceeded in comparison
0.015 s 4 KBi
Puntos totales: 27 / 100

Código

mem = {}


def contar(valor, monedas):
    global mem

    if valor == 0:
        return 1

    if valor < 0:
        return 0

    if valor in mem:
        return mem[valor]

    combs = 0

    for moned in monedas:
        combs += contar(valor - moned, monedas)

    mem[valor] = combs

    return combs


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

for i in range(M):
    valor = int(input())

    print(contar(valor, monedas))