Problem p03128 (python)

Fixed submission:
import os, sys, re, math
sys.setrecursionlimit(100000)
N,M = list(map(int,input().split(' ')))
A = list(map(int,input().split(' ')))

match = [100,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = str(a) + tmp
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [10000000,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = max(str(a) + tmp, tmp + str(a))
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = max(str(a) + tmp, tmp + str(a))
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m == 0:
        return ""

    ret = None
    for a in A:
        tmp = None
        if m - match[a] >= 0:
            tmp = doit(m - match[a])
            if tmp is not None:
                tmp = str(a) + tmp
                if ret is not None:
                    if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):
                        ret = tmp
                else:
                    ret = tmp

    memo[m] = ret
    return ret

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]

    max_v = 0
    for a in A:
        if m - match[a] == 0:
            max_v = max(int(max_v), int(str(a)))
        elif m > match[a]:
            tmp = doit(m - match[a])
            if tmp != '0':
                max_v = max(int(max_v), int(str(a) + doit(m - match[a])))

    memo[m] = str(max_v)
    return str(max_v)

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m <= 0:
        return ''

    max_v = '0'
    for a in A:
        tmp = doit(m - match[a])
        if m >= match[a] and tmp is not None:
            max_v = max(max_v, str(a) + doit(m - match[a]),key= lambda x: int(x))

    if max_v != '0':
        memo[m] = max_v
        return max_v
    else:
        return None

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]
    if m <= 0:
        return ''

    max_v = '0'
    for a in A:
        tmp = doit(m - match[a])
        if m >= match[a] and tmp is not None:
            max_v = max(max_v, str(a) + doit(m - match[a]),key= lambda x: int(x))

    if max_v != '0':
        memo[m] = max_v
        return max_v
    else:
        return None

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]

    max_v = '-9'
    for a in A:
        if m - match[a] == 0:
            max_v = max(max_v, str(a), key=lambda x: int(x))
        elif m - match[a] >= 0:
            max_v = max(max_v, doit(m - match[a]) + str(a), key=lambda x: int(x))
    if max_v != '':
        memo[m] = str(max_v)
        return str(max_v)
    else:
        return '-9'

print(doit(N))

Buggy submission (verdict: Runtime Error):
import os, sys, re, math

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

match = [-1,2,5,5,4,5,6,3,7,6]
memo = {}

def doit(m):
    if m in memo:
        return memo[m]

    max_v = 0
    for a in A:
        if m - match[a] == 0:
            max_v = max(int(max_v), int(str(a)))
        elif m > match[a]:
            tmp = doit(m - match[a])
            if tmp != '0':
                max_v = max(int(max_v), int(str(a) + doit(m - match[a])))

    memo[m] = str(max_v)
    return str(max_v)

print(doit(N))