Problem p03128 (python)

Fixed submission:
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i

dp = [[0 for j in range(10)] for i in range(N)]
for i in L.items():
  if i[0] - 1 < N:
    dp[i[0] - 1][i[1]] = 1
for i in range(N):
  if max(dp[i]) == 0:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t[j[1]] += 1
      if sum(t) > sum(dp[k]):
        dp[k] = t
      else:
        for ii in range(9, 0, -1):
          if t[ii] > dp[k][ii]:
            dp[k] = t
            break
          elif t[ii] < dp[k][ii]:
            break
          
t = dp[-1]
Ans = ""
for i in range(9, 0, -1):
  for j in range(t[i]):
    Ans += str(i)
    
print(Ans)

Buggy submission (verdict: Runtime Error):
#わからんテスト
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i

dp = [[0 for j in range(10)] for i in range(N)]
for i in L.items():
  dp[i[0] - 1][i[1]] = 1

Buggy submission (verdict: Runtime Error):
#わからんテスト
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i

dp = [[0 for j in range(10)] for i in range(N)]
for i in L.items():
  dp[i[0] - 1][i[1]] = 1
for i in range(N):
  if max(dp[i]) == 0:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t[j[1]] += 1
      if sum(t) > sum(dp[k]):
        dp[k] = t
      else:
        for ii in range(9, 0, -1):
          if t[ii] > dp[k][ii]:
            dp[k] = t
            break
          elif t[ii] < dp[k][ii]:
            break

Buggy submission (verdict: Runtime Error):
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i
  
dp = [[0 for j in range(10)] for i in range(N)]
for i in L.items():
  dp[i[0] - 1][i[1]] = 1
for i in range(N):
  if max(dp[i]) == 0:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t[j[1]] += 1
      if sum(t) > sum(dp[k]):
        tt = dp[k]
        dp[k] = t
        del tt
      else:
        for ii in range(9, 0, -1):
          if t[ii] > dp[k][ii]:
            tt = dp[k]
            dp[k] = t
            del tt
            break
          elif t[ii] < dp[k][ii]:
            break
          
t = dp[-1]
Ans = ""
for i in range(9, 0, -1):
  for j in range(t[i]):
    Ans += str(i)
    
print(Ans)

Buggy submission (verdict: Runtime Error):
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i
  
dp = [[0 for j in range(10)] for i in range(N)]
for i in L.items():
  dp[i[0] - 1][i[1]] = 1
for i in range(N):
  if max(dp[i]) == 0:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t[j[1]] += 1
      if sum(t) > sum(dp[k]):
        dp[k] = t
      else:
        for ii in range(9, 0, -1):
          if t[ii] > dp[k][ii]:
            dp[k] = t
            break
          elif t[ii] < dp[k][ii]:
            break
          
t = dp[-1]
Ans = ""
for i in range(9, 0, -1):
  for j in range(t[i]):
    Ans += str(i)
    
print(Ans)

Buggy submission (verdict: Runtime Error):
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i
  
dp = [[0 for j in range(10)] for i in range(N)]
for i in L.items():
  dp[i[0] - 1][i[1]] = 1
for i in range(N):
  if max(dp[i]) == 0:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t[j[1]] += 1
      if sum(t) > sum(dp[i]):
        dp[k] = t
        continue
      for ii in range(9, 0, -1):
        if t[ii] > dp[k][ii]:
          dp[k] = t
          break
        elif t[ii] < dp[k][ii]:
          break
          
t = dp[-1]
Ans = ""
for i in range(9, 0, -1):
  for k in range(t[i]):
    Ans += str(i)
    
print(Ans)

Buggy submission (verdict: Runtime Error):
import copy

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

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i
  
dp = [[0 for j in range(10)] for i in range(N)]
ja = [0 for j in range(10)]
for i in L.items():
  dp[i[0] - 1][i[1]] = 1
for i in range(N):
  if dp[i] == ja:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t[j[1]] += 1
      for ii in range(9, 0, -1):
        if t[ii] > dp[k][ii]:
          dp[k] = t
          break
        elif t[ii] < dp[k][ii]:
          break
          
t = dp[-1]
Ans = ""
for i in range(9, 0, -1):
  for k in range(t[i]):
    Ans += str(i)
    
print(Ans)

Buggy submission (verdict: Runtime Error):
import copy

def ano_onnano_code(L, x):
  ok = 0
  ng = len(L)
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if L[mid] > x:
      ok = mid
    else:
      ng = mid
  if L[ok] < x:
    return ok
  else:
    return ng
      
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))

t = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
L = {}
for i in A:
  if t[i] in L:
    if L[t[i]] < i:
      L[t[i]] = i
  else:
    L[t[i]] = i
  
dp = [[] for i in range(N)]

for i in L.items():
  dp[i[0] - 1] = [i[1]]
for i in range(N):
  if dp[i] == []:
    continue
  for j in L.items():
    k = i + j[0]
    if k < N:
      t = copy.deepcopy(dp[i])
      t.insert(ano_onnano_code(t, j[1]), j[1])
      a = dp[k] == []
      b = len(t) > len(dp[k])
      c = t > dp[k]
      if a or b or c:
        dp[k] = t

t = [str(i) for i in dp[-1]]
print("".join(t))

Buggy submission (verdict: Runtime Error):
def mina(t, i, L):
  return True

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

A = list(map(int, input().split()))

t = [2, 5, 5, 4, 5, 6, 3, 7, 6]

A.sort(reverse = True)
D = {}
L = []
X = []
for i in A:
  if t[i - 1] not in D:
    D[t[i - 1]] = i
    L.append(t[i - 1])
    X.append([i, t[i - 1]])

L.sort()

Lmin = N // L[0]
Lmod = N % L[0]

F = True
if Lmod != 0:
  while F:
    Lmin -= 1
    Lmod += L[0]
    t = Lmod
    for i in L[1:]:
      if mina(t, i, L[1:]) == True:
        F = False
        break
  
  X.sort(reverse = True)
  for i in X:
    if i != L[0]:
      k = t - i[1]
      if k == 0:
        List = [i[0]]
        break
      elif k > 0:
        for j in X:
          if i != L[0]:
            if k - j[1] == 0:
              List = [i[0], j[0]]
              F = True
              break
        if F:
          break

Ans = [str(D[L[0]]) for i in range(Lmin)]
if Lmod != 0:
  if len(List) == 1:
    if L[0] < List[0]:
      Ans = [str(List[0])] + Ans
    else:
      Ans = Ans + [str(List[0])]
  else:
    List.sort(reverse = True)
    if L[0] > List[0]:
      Ans += [str(List[0]), str(List[1])]
    elif L[0] < List[1]:
      Ans = [str(List[0]), str(List[1])] + Ans
    else:
      Ans = [str(List[0])] + Ans + [str(List[1])]

print("".join(Ans))

Buggy submission (verdict: Runtime Error):
def mina(t, i, L):
  t -= i
  if t == 0:
    return True
  elif t < 0:
    return False
  else:
    for i in L:
      if mina(t, i, L) == True:
        return True
    return False

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

A = list(map(int, input().split()))

t = [2, 5, 5, 4, 5, 6, 3, 7, 6]

A.sort(reverse = True)
D = {}
L = []
X = []
for i in A:
  if t[i - 1] not in D:
    D[t[i - 1]] = i
    L.append(t[i - 1])
    X.append([i, t[i - 1]])

L.sort()

Lmin = N // L[0]
Lmod = N % L[0]

F = True
if Lmod != 0:
  while F:
    Lmin -= 1
    Lmod += L[0]
    t = Lmod
    for i in L[1:]:
      if mina(t, i, L[1:]) == True:
        F = False
        break
  
  X.sort(reverse = True)
  for i in X:
    if i != L[0]:
      k = t - i[1]
      if k == 0:
        List = [i[0]]
        break
      elif k > 0:
        for j in X:
          if i != L[0]:
            if k - j[1] == 0:
              List = [i[0], j[0]]
              F = True
              break
        if F:
          break

Ans = [str(D[L[0]]) for i in range(Lmin)]
if Lmod != 0:
  if len(List) == 1:
    if L[0] < List[0]:
      Ans = [str(List[0])] + Ans
    else:
      Ans = Ans + [str(List[0])]
  else:
    List.sort(reverse = True)
    if L[0] > List[0]:
      Ans += [str(List[0]), str(List[1])]
    elif L[0] < List[1]:
      Ans = [str(List[0]), str(List[1])] + Ans
    else:
      Ans = [str(List[0])] + Ans + [str(List[1])]

print("".join(Ans))

Buggy submission (verdict: Runtime Error):
def mina(t, i, L):
  t -= i
  if t == 0:
    return True
  elif t < 0:
    return False
  else:
    for i in L:
      if mina(t, i, L) == True:
        return True
    return False

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

A = list(map(int, input().split()))

t = [2, 5, 5, 4, 5, 6, 3, 7, 6]

A.sort(reverse = True)
D = {}
L = []
X = []
for i in A:
  if t[i - 1] not in D:
    D[t[i - 1]] = i
    L.append(t[i - 1])
    X.append([i, t[i - 1]])

L.sort()

Lmin = N // L[0]
Lmod = N % L[0]

F = True
if Lmod != 0:
  while F:
    Lmin -= 1
    Lmod += L[0]
    t = Lmod
    for i in L[1:]:
      if mina(t, i, L[1:]) == True:
        F = False
        break
  
  X.sort(reverse = True)
  for i in X:
    k = t - i[1]
    if k == 0:
      List = [i[0]]
      break
    elif k > 0:
      for j in X:
        if k - j[1] == 0:
          List = [i[0], j[0]]

Ans = [str(D[L[0]]) for i in range(Lmin)]
if Lmod != 0:
  if len(List) == 1:
    if L[0] < List[0]:
      Ans = [str(List[0])] + Ans
    else:
      Ans = Ans + [str(List[0])]
  else:
    List.sort(reverse = True)
    if L[0] > List[0]:
      Ans += [str(List[0]), str(List[1])]
    elif L[0] < List[1]:
      Ans = [str(List[0]), str(List[1])] + Ans
    else:
      Ans = [str(List[0])] + Ans + [str(List[1])]

print("".join(Ans))