problem_id stringlengths 6 6 | user_id stringlengths 10 10 | time_limit float64 1k 8k | memory_limit float64 262k 1.05M | problem_description stringlengths 48 1.55k | codes stringlengths 35 98.9k | status stringlengths 28 1.7k | submission_ids stringlengths 28 1.41k | memories stringlengths 13 808 | cpu_times stringlengths 11 610 | code_sizes stringlengths 7 505 |
|---|---|---|---|---|---|---|---|---|---|---|
p03128 | u067729694 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nimport sys\nINT_MIN = sys.maxsize * -1\nmatch = [-100,2,5,5,4,5,6,3,7,6]\nCHOICES = []\nfor i in A:\n if (i == 6) and (9 in A):\n continue\n if (i == 3) and (5 in A):\n continue\n if (i == 2) and (3 in A or 5 in A):\n continue\n CHOICES.append([i, match[i]])\nCHOICES.sort(reverse=True)\n\nans = [0]\n#print(CHOICES)\nfor i in range(1,N+1):\n ans.append(INT_MIN)\n for c in CHOICES:\n if i - c[1] == 0:\n ans[i] = max(ans[i], int(str(c[0])))\n break\n elif i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:\n ans[i] = max(ans[i], int(str(c[0]) + str(ans[i - c[1]])))\n break\n\nprint(ans[N])\n\n\n', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\ndef dp(n, i):\n if n == 0:\n return 0\n if n < 0:\n return None\n if i == len(CHOICES):\n return None\n \n ret1 = dp(n - CHOICES[i][1], i)\n if ret1 == None:\n ret1 = 0\n elif ret1 == 0:\n ret1 = int(str(CHOICES[i][0]))\n else:\n ret1 = int(str(CHOICES[i][0]) + str(ret1))\n\n ret2 = dp(n, i+1)\n if ret2 == None:\n ret2 = 0\n else:\n ret2 = ret2\n \n return max(ret1, ret2)\n\n\n\nmatch = [-100,2,5,5,4,5,6,3,7,6]\nCHOICES = []\nfor i in A:\n if (i == 6) and (9 in A):\n continue\n if (i == 3) and (5 in A):\n continue\n if (i == 2) and (3 in A or 5 in A):\n continue\n CHOICES.append([i, match[i]])\n\nprint(CHOICES)\nans = dp(N,0)\nprint(ans)\n \n', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nimport sys\nINT_MIN = sys.maxsize * -1\nmatch = [-100,2,5,5,4,5,6,3,7,6]\nCHOICES = []\nfor i in A:\n if (i == 6) and (9 in A):\n continue\n if (i == 3) and (5 in A):\n continue\n if (i == 2) and (3 in A or 5 in A):\n continue\n CHOICES.append([i, match[i]])\nCHOICES.sort(reverse=True)\n\nans = [0]\n#print(CHOICES)\nfor i in range(1,N+1):\n ans.append(INT_MIN)\n for c in CHOICES:\n \n # ans[i] = max(ans[i], int(str(c[0])))\n #elif i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:\n # ans[i] = max(ans[i], int(str(c[0]) + str(ans[i - c[1]])))\n\n if i - c[1] >= 0 and ans[i - c[1]] != INT_MIN:\n ans[i] = max(ans[i], c[0] + ans[i - c[1]] * 10)\n\nprint(ans[N])\n\n\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s139713402', 's376444936', 's686837800'] | [7028.0, 3956.0, 14820.0] | [276.0, 2104.0, 119.0] | [730, 814, 814] |
p03128 | u067983636 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\ncost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ncan_cost = sorted([cost[a] for a in A])\nD = {}\nfor a in A:\n c = cost[a]\n D[c] = max(a, D.setdefault(c, -1))\n\nmin_cost = can_cost[0]\nmin_cost_num = D[min_cost]\n\n\ndef f2(v, l, num):\n L = list(str(v))\n min_cost = cost[int(num)]\n num = D.setdefault(min_cost + l, -1)\n if num == -1:\n return -1\n\n min_cost_num = D[min_cost]\n L[L.index(str(min_cost_num))] = str(num)\n L.sort(reverse=True)\n return int("".join(L))\n\n\ndef f(v, l):\n L = list(str(v))\n set_L = set(L)\n L2 = [f2(v, l, num) for num in set_L]\n return max(L2)\n\ndef g(K, r)\n\n temp = int("".join([str(min_cost_num)] * K))\n dp = [[-1 for _ in range(min(r, K) + 1)] for __ in range(r + 1)]\n dp[0][0] = temp\n\n for k in range(min(r, K)):\n for n in range(r):\n v = dp[n][k]\n if v == -1:\n continue\n for l in range(1, r - n + 1):\n dp[n + l][k + 1] = max(dp[n + l][k + 1], f(v, l))\n return max(dp[r])\n\nK = N // min_cost\nr = N - K * min_cost\nres = g(K, r)\nif g(K, r) == -1:\n res = g(K - 1, r + min_cost)\nprint(res)', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\ncost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ncan_cost = sorted([cost[a] for a in A])\nD = {}\nfor a in A:\n c = cost[a]\n D[c] = max(a, D.setdefault(c, -1))\n\nmin_cost = can_cost[0]\nmin_cost_num = D[min_cost]\n\n\ndef f2(v, l, num):\n L = list(str(v))\n min_cost = cost[int(num)]\n num = D.setdefault(min_cost + l, -1)\n if num == -1:\n return -1\n\n min_cost_num = D[min_cost]\n L[L.index(str(min_cost_num))] = str(num)\n L.sort(reverse=True)\n return int("".join(L))\n\n\ndef f(v, l):\n L = list(str(v))\n set_L = set(L)\n L2 = [f2(v, l, num) for num in set_L]\n return max(L2)\n\ndef g(K, r):\n temp = int("".join([str(min_cost_num)] * K))\n dp = [[-1 for _ in range(min(r, K) + 1)] for __ in range(r + 1)]\n dp[0][0] = temp\n\n for k in range(min(r, K)):\n for n in range(r):\n v = dp[n][k]\n if v == -1:\n continue\n for l in range(1, r - n + 1):\n dp[n + l][k + 1] = max(dp[n + l][k + 1], f(v, l))\n return max(dp[r])\n\nK = N // min_cost\nr = N - K * min_cost\nres = g(K, r)\nwhile res == -1:\n K -= 1\n r += min_cost\n res = g(K, r)\nprint(res)'] | ['Runtime Error', 'Accepted'] | ['s178419022', 's860106078'] | [3064.0, 3192.0] | [18.0, 22.0] | [1197, 1210] |
p03128 | u069602573 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m=map(int, input().split()) \na=list(map(int, input().split())) \nneedNum = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\na.sort()\nneed = list()\nfor i in range(m):\n need.append(needNum[a[i]])\n\nminNum = a[need.index(min(need))] \nminNeed = min(need) の必要数\n\ndigit = n//minNeed\nremain = n % minNeed\n\n\nout = 0\nfor i in range(digit):\n if i == digit-1:\n if remain != 0:\n for j in range(m):\n if minNeed +remain == needNum[a[-1-j]]:\n out = a[-1-j]\n break\n else:\n out = minNum\n\n elif remain != 0:\n for j in range(m):\n if minNeed+remain >= needNum[a[-1-j]]:\n out = a[-1-j]\n remain -= needNum[a[-1-j]]-minNeed\n break\n else:\n out = minNum\n\n print( out, end="")', 'n,m=map(int, input().split()) \nA=list(map(int, input().split())) \nnum = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nA.sort(reverse=True) \n\ndp = [-1*float("inf")]*(n+1) \n\ndp[0] = 0\nfor a in A:\n if num[a] <= n:\n dp[num[a]] = 1\n\nfor i in range(1,n+1):\n for a in A:\n if i - num[a] >= 0:\n dp[i] = max(dp[i], dp[i-num[a]] + 1)\n\nans = ""\nfor i in range(dp[n]): \n for a in A: \n if n-num[a] >= 0 and dp[n-num[a]] == dp[n]-1:\n ans += str(a)\n n -= num[a]\n break\n \nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s875724196', 's554570081'] | [3956.0, 3308.0] | [30.0, 86.0] | [957, 787] |
p03128 | u075012704 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['\nN, M = map(int, input().split())\nCosts = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}\nA = sorted(list(map(int, input().split())), reverse=True) \n\n\n\ndp = [-float(\'inf\')] * (N + 1)\ndp[0] = 0\n\n\nfor a in A:\n cost = Costs[a]\n for j in range(N + 1):\n if cost > j:\n continue\n dp[j] = max(dp[j], dp[j - cost] + 1)\n\nprint(\'x\')\n\n# ans = ""\n\n\n\n# cost = Costs[a]\n\n\n\n# ans += str(a)\n# marker = marker - cost\n# break\n# \n# print(ans)\n', 'N, M = map(int, input().split())\nCosts = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}\nA = sorted(list(map(int, input().split())), reverse=True) \n\n\n\ndp = [-float(\'inf\')] * (N + 1)\ndp[0] = 0\n\n\nfor a in A:\n cost = Costs[a]\n for j in range(N + 1):\n if cost > j:\n continue\n dp[j] = max(dp[j], dp[j - cost] + 1)\n\n\n\nans = ""\nmarker = N \nwhile dp[marker]: \n for a in A: \n cost = Costs[a]\n \n \n if marker - cost < 0:\n continue\n \n \n \n if dp[marker - cost] == dp[marker] - 1:\n ans += str(a)\n marker = marker - cost\n break\n\nprint(ans)\n'] | ['Wrong Answer', 'Accepted'] | ['s503100386', 's190566320'] | [3316.0, 3316.0] | [61.0, 81.0] | [1180, 1178] |
p03128 | u077337864 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["n, m = map(int, input().split())\nalist = list(sorted(map(int, input().split())))[::-1]\nmd = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\ndp = [[0, []] for _ in range(n + 1)]\n\nfor i in range(2, n+1):\n maxn = 0\n maxt = []\n for a in alist:\n if i - md[a] < 0:\n continue\n if maxn < dp[i-md[a]][0] + 1:\n maxn = dp[i-md[a]][0] + 1\n maxt = dp[i-md[a]][1][:]\n maxt.append(a)\n dp[i] = [maxn, maxt]\nprint(*sorted(dp[n][1], key=lambda x: -x), sep='')", "n, m = map(int, input().split())\nalist = list(sorted(map(int, input().split())))[::-1]\nmd = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\ndp = [-float('inf') for _ in range(n+1)]\ndp[0] = 0\n\nfor i in range(n+1):\n for a in alist:\n if i - md[a] >= 0:\n if dp[i] < dp[i - md[a]] + 1:\n dp[i] = dp[i - md[a]] + 1\n\nans = ''\nres = n\nwhile i > 0:\n for a in alist:\n if i >= md[a] and dp[i]-1 == dp[i-md[a]]:\n ans += str(a)\n i -= md[a]\n break\n\nprint(ans)\n"] | ['Wrong Answer', 'Accepted'] | ['s695849212', 's728169159'] | [225612.0, 3316.0] | [624.0, 74.0] | [470, 479] |
p03128 | u085717502 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['\n# coding: utf-8\n\n# In[46]:\n\n\ndef main():\n N,M = map(int, input().split())\n A = list(map(int, input().split()))\n \n match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n \n result = [-1 for _ in range(N+1)]\n result[0] = 0\n \n print(result)\n \n for i in range(1, N+1):\n for a in A:\n if i < match[a]:\n print(i,a,result)\n continue\n result[i] = max(result[i], result[i-match[a]]*10+a)\n print(i,a,result)\n \n print(result[N])\n\n\n# In[47]:\n\n\nmain()\n\n', '\n# coding: utf-8\n\n# In[1]:\n\n\ndef main():\n N,M = map(int, input().split())\n A = list(map(int, input().split()))\n \n match = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n \n result = [-1 for _ in range(N+1)]\n result[0] = 0\n \n #print(result)\n \n for i in range(1, N+1):\n for a in A:\n if i < match[a]:\n #print(i,a,result)\n continue\n result[i] = max(result[i], result[i-match[a]]*10+a)\n #print(i,a,result)\n \n print(result[N])\n\n\n# In[2]:\n\n\nmain()\n\n'] | ['Runtime Error', 'Accepted'] | ['s440622103', 's090941326'] | [134940.0, 14388.0] | [2063.0, 121.0] | [533, 534] |
p03128 | u087917227 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N,M = map(int, input().split())\nam = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\nf = [-1]*10010\nf[0]=0\nfor i in range(1,N+1):\n for x in am:\n if i-c[x] >= 0:\n f[i] = max(f[i], f[i-c[x]]*10 +x)\n \nprint(f[n])', 'N,M = map(int, input().split())\nam = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\nf = [-1]*10010\nf[0]=0\nfor i in range(1,n+1):\n for x in am:\n if i-c[x] >= 0:\n f[i] = max(f[i], f[i-c[x]]*10 +x)\n \nprint(f[n])', 'N,M = map(int, input().split())\nam = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\nf = [-1]*10010\nf[0]=0\nfor i in range(1,n+1):\n for x in a:\n if i-c[x] >= 0:\n f[i] = max(f[i], f[i-c[x]]*10 +x)\n \nprint(f[n])', 'N,M = map(int, input().split())\nam = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\nf = [-1]*10010\nf[0]=0\nfor i in range(1,N+1):\n for x in am:\n if i-c[x] >= 0:\n f[i] = max(f[i], f[i-c[x]]*10 +x)\n \nprint(f[N])'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s044692153', 's572510261', 's694331947', 's030881309'] | [14388.0, 3064.0, 3064.0, 14388.0] | [157.0, 17.0, 17.0, 154.0] | [251, 251, 250, 251] |
p03128 | u102278909 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['# coding: utf-8\n\nimport sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nneed = [0,2,5,5,4,5,6,3,7,6]\n\ndp = [-1] * (N + 1)\ndp[0] = 0\n\nfor i in range(N + 1):\n for a in A:\n if i + need[a] <= N:\n dp[i + need[a]] = max(dp[i + need[a]], dp[i] * 10 + a)\n\nprint(dp)\n\n', '# coding: utf-8\n\nimport sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nneed = [0,2,5,5,4,5,6,3,7,6]\n\ndp = [-1] * (N + 1)\ndp[0] = 0\n\nfor num in A:\n required = need[num]\n\n for i in range(N - required + 1):\n if dp[i] == -1:\n continue\n \n dp[i + required] = max(dp[i + required], dp[i] * 10 + num)\n\nprint(dp[-1])\n\n', '# coding: utf-8\n\nimport sys\ninput = sys.stdin.readline\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nneed = [0,2,5,5,4,5,6,3,7,6]\n\ndp = [-1] * (N + 1)\ndp[0] = 0\n\nfor i in range(N + 1):\n for a in A:\n if i + need[a] <= N:\n dp[i + need[a]] = max(dp[i + need[a]], dp[i] * 10 + a)\n\nprint(dp[-1])\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s479969051', 's561849446', 's398277742'] | [88068.0, 14448.0, 14692.0] | [1542.0, 142.0, 171.0] | [358, 446, 362] |
p03128 | u102461423 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import itertools\n\nN,M = map(int,input().split())\nA = [int(x) for x in input().split()]\nL = [100,2,5,5,4,5,6,3,7,6]\n\nlen_set = set(L[x] for x in A)\n\nINF = 10**18\ncan_make = [INF]*(N+1)\ncan_make[0] = 0 \n\nfor n in range(1,N+1):\n for x in len_set:\n if n-x >= 0 and can_make[n] > can_make[n-x] + 1:\n can_make[n] = can_make[n-x] + 1\n\nanswer = []\n\nA.sort(reverse = True)\n\nfor a in A:\n while N-L[a] >= 0 and can_make[N] == can_make[N-L[a]]+1:\n answer.append(str(a))\n N -= L[a]\n \nanswer = ''.join(answer)\n\nprint(answer)", "import itertools\nfrom collections import defaultdict\n\nN,M = map(int,input().split())\nA = [int(x) for x in input().split()]\nL = [None,2,5,5,4,5,6,3,7,6]\n\nl_to_n = [[] for _ in range(10)]\nfor a in A[1:]:\n l_to_n[L[a]].append(a)\n \nl_to_n = [(i,max(x)) for i,x in enumerate(l_to_n) if x]\n\nse = {0} \n\nfor l,_ in l_to_n:\n se = {x+y for x,y in itertools.product(se,range(0,1000,l)) if x+y < 1000}\n\nanswer = ''\nm_L,x = l_to_n[0]\nwhile N > 100:\n N -= m_L\n answer += str(x)\n \nfor l,x in l_to_n:\n while N-l in se:\n N -= l\n answer += str(x)\n if N == 0:\n break\n\nanswer = ''.join(sorted(answer,reverse=True))\n\nprint(answer)", "import itertools\n\nN,M = map(int,input().split())\nA = [int(x) for x in input().split()]\nL = [100,2,5,5,4,5,6,3,7,6]\n\nlen_set = set(L[x] for x in A)\n\nINF = 10**18\ncan_make = [-INF]*(N+1)\ncan_make[0] = 0 \n\nfor n in range(1,N+1):\n for x in len_set:\n if n-x >= 0 and can_make[n] < can_make[n-x] + 1:\n can_make[n] = can_make[n-x] + 1\n\nanswer = []\n\nA.sort(reverse = True)\n\nfor a in A:\n x = L[a]\n while N-x >= 0 and can_make[N] == can_make[N-x]+1:\n answer.append(str(a))\n N -= x\n \nanswer = ''.join(answer)\nprint(answer)"] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s554104372', 's897196507', 's119615489'] | [3432.0, 3436.0, 3676.0] | [39.0, 117.0, 40.0] | [648, 656, 650] |
p03128 | u138486156 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n, m = map(int, input().split())\na = list(map(int, input().split()))\ndp = [0] * (n+1)\nfor i in range(1, n+1):\n for j in a:\n cost_j = int("0255456376"[j])\n if i- cost_j >= 0:\n dp[i] = max(dp[i], j+dp[i-cost_j]*10)\nprint(dp[n])\n', 'n, m = map(int, input().split())\na = list(map(int, input().split()))\ninf = float("inf")\ndp = [-inf] * (n+1)\ndp[0] = 0\nfor i in range(1, n+1):\n for j in a:\n cost_j = int("0255456376"[j])\n if i- cost_j >= 0:\n dp[i] = max(dp[i], j+dp[i-cost_j]*10)\n print(dp)\nans = dp[n]\nif ans == -inf:\n ans = 0\nprint(ans)\n\n', 'n, m = map(int, input().split())\na = list(map(int, input().split()))\ninf = float("inf")\ndp = [-inf] * (n+1)\ndp[0] = 0\nfor i in range(1, n+1):\n for j in a:\n cost_j = int("0255456376"[j])\n if i- cost_j >= 0:\n dp[i] = max(dp[i], j+dp[i-cost_j]*10)\n\nans = dp[n]\nif ans == -inf:\n ans = 0\nprint(ans)\n\n'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s183004101', 's207688540', 's193866374'] | [14388.0, 134720.0, 14388.0] | [170.0, 2104.0, 169.0] | [254, 343, 326] |
p03128 | u139112865 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["#118_D\nch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}\n\ndef max_num(x,y):\n if x==-1:\n return -1\n if x==0:\n return y\n l=list(str(x))+[str(y)]\n l.sort(reverse=True)\n return int(''.join(l))\n\nn,m=map(int,input().split())\na=list(map(int,input().split()))\n\ndp=[-1 for _ in range(n+1)]\ndp[0]=0\nfor i in range(1,n+1):\n res=-1\n for x in a:\n if i-ch[x]>=0:\n res=max(res,max_num(dp[i-ch[x]],x))\n dp[i]=res\n \nprint(dp)", '#118_D\nch={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}\n\nn,m=map(int,input().split())\na=list(map(int,input().split()))\n\ndp=[-1 for _ in range(n+1)]\ndp[0]=0\nfor i in range(1,n+1):\n res=-1\n for x in a:\n if i-ch[x]>=0:\n res=max(res,dp[i-ch[x]]*10+x)\n dp[i]=res\n \nprint(dp[n])'] | ['Wrong Answer', 'Accepted'] | ['s885323713', 's972069410'] | [31664.0, 14516.0] | [2104.0, 146.0] | [469, 294] |
p03128 | u141786930 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['# D - Match Matching\n\nN, M = map(int, input().split())\nA = list(int(x) for x in input().split())\nmatch_list = [(0, 6), (1, 2), (2, 5), (3, 5), (4, 4), (5, 5), (6, 6), (7, 3), (8, 7), (9, 6)]\nMA = []\nfor a in A:\n MA.append(MATCH[a])\nMA.sort(key=lambda x: x[1])\n\ndef dfs(tmp, s):\n global ans\n if s == N:\n ans = max(ans, tmp) \n for ma in MA:\n if s+ma[1] <= N:\n tmp = tmp*10 + ma[0]\n dfs(tmp, s + ma[1])\n tmp //= 10\n\ntmp = 0\nans = 0\ndfs(tmp, 0)\nprint(ans)', "# D - Match Matching\n\nN, M = map(int, input().split())\nA = list(int(x) for x in input().split())\nmatch_list = [('0', 6), ('1', 2), ('2', 5), ('3', 5), ('4', 4), ('5', 5), ('6', 6), ('7', 3), ('8', 7), ('9', 6)]\nMA = []\nfor a in A:\n MA.append(match_list[a])\nMA.sort(key=lambda x: x[0], reverse=True)\n\n\ndp = [-1] * (N+1)\ndp[0] = 0\nfor i in range(N+1):\n for j in range(M):\n if i-MA[j][1] >= 0:\n dp[i] = max(dp[i], dp[i-MA[j][1]] + 1)\n\nremain_keta = dp[N]\nremain_match = N\nans = ''\nfor i in range(dp[N]):\n for ma in MA:\n \n \n if remain_match >= ma[1] and dp[remain_match - ma[1]] == remain_keta - 1:\n ans += ma[0]\n remain_keta -= 1\n remain_match -= ma[1]\n break\n\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s165433579', 's418017551'] | [3064.0, 3420.0] | [18.0, 92.0] | [513, 921] |
p03128 | u160244242 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["n, m = map(int, input().split())\nlst = list(map(int, input().split()))\nlst = sorted(lst, key = lambda x:-x)\ndic = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\ns = set()\nfor i in lst:\n s.add(dic[i])\ns = list(sorted(s))\n\ndp = [0] * (n+1)\nfor i in range(0, n+1):\n a = 0\n max_a = -1\n for j in s:\n if i-j < 0:\n continue\n if i == j and dp[i-j] == 0:\n a = 1\n elif i - j > 0 and dp[i-j] > 0:\n a = dp[i-j] + 1\n if max_a < a:\n max_a = a\n dp[i] = max_a\n\ndef out(dp, dic, n, ans, ans_digit, lst):\n if len(ans) == ans_digit-1:\n for i in lst:\n if n == dic[i]:\n return ans + str(i)\n else:\n for i in lst:\n if n - dic[i] >= 0:\n if dp[n] -1 == dp[n-dic[i]]:\n ans += str(i)\n next_n = n - dic[i]\n break\n return out(dp, dic, next_n, ans, ans_digit, lst)\n \nprint(out(dp, dic, n, '', dp[n], lst))", "n, m = map(int, input().split())\nlst = list(map(int, input().split()))\nlst = sorted(lst, key = lambda x:-x)\ndic = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\ns = set()\nfor i in lst:\n s.add(dic[i])\ns = list(sorted(s))\n\ndp = [0] * (n+1)\nfor i in range(0, n+2):\n max_a = 0\n for j in s:\n if i - j >= 0:\n a = dp[i-j] + 1\n if max_a < a:\n max_a = a\n dp[i] = max_a\n\ndef out(dp, dic, n, ans, ans_digit):\n if len(ans) == ans_digit-1:\n for i in lst:\n if n == dic[i]:\n return ans + str(i)\n else:\n for i in lst:\n if n - dic[i] >= 0:\n if dp[n] -1 == dp[n-dic[i]]:\n ans += str(i)\n next_n = n - dic[i]\n break\n return out(dp, dic, next_n, ans, ans_digit)\n \nprint(out(dp, dic, n, '', dp[n]))", "n, m = map(int, input().split())\nlst = list(map(int, input().split()))\nlst = sorted(lst, key = lambda x:-x)\ndic = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\ns = set()\nfor i in lst:\n s.add(dic[i])\ns = list(sorted(s))\n\ndp = [0] * (n+1)\nfor i in range(0, n+1):\n a = 0\n max_a = 0\n for j in s:\n if i-j < 0:\n pass\n elif i == j:\n a = 1\n elif i - j > 0 and dp[i-j] > 0:\n a = dp[i-j] + 1\n if max_a < a:\n max_a = a\n dp[i] = max_a\n\nans = ''\nans_digit = dp[n]\nwhile len(ans) < ans_digit:\n if len(ans) == ans_digit-1:\n for i in lst:\n if n == dic[i]:\n ans += str(i)\n break\n else:\n for i in lst:\n if n - dic[i] >= 0:\n if dp[n] -1 == dp[n-dic[i]]:\n ans += str(i)\n n -= dic[i]\n break\n \nprint(ans)"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s036235691', 's741839321', 's757069466'] | [3188.0, 3316.0, 3408.0] | [44.0, 37.0, 76.0] | [1001, 871, 917] |
p03128 | u166696759 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\nK = [0, 2, 5, 5, 4, 5 ,6, 3, 7, 6]\ndp = [[-1,[]]for i in range(50000)]\ndef clc(B):\n B.sort(reverse=True)\n res = 0\n for b in B:\n res *= 10\n res += b\n return res\nfor i in range(N):\n for a in A:\n li = dp[i][1].copy()\n li.append(a)\n score = clc(li)\n if dp[i+K[a]][0] < score:\n dp[i+K[a]][1] = li\n dp[i+K[a]][0] = score\nprint(clc(dp[N][1]))', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\nnum = [0, 2, 5, 5, 4, 5 ,6, 3, 7, 6]\ndp = ["" for i in range(N+30)]\nfor i in range(N):\n if i!=0 and dp[i]=="":\n continue\n for a in A:\n tmpscore = dp[i]+str(a)\n if len(dp[i+num[a]]) < len(tmpscore):\n dp[i+num[a]] = tmpscore\n elif len(dp[i+num[a]]) > len(tmpscore):\n continue\n else:\n dp[i+num[a]] = max(dp[i+num[a]], tmpscore)\nprint(dp[N])'] | ['Wrong Answer', 'Accepted'] | ['s498818770', 's831547163'] | [70268.0, 30196.0] | [2108.0, 177.0] | [483, 480] |
p03128 | u169138653 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\ninput=sys.stdin.readline\nn,m=map(int,input().split())\na=list(map(int,input().split()))\nd=dict()\nneed=[0,2,5,5,4,5,6,3,7,6]\nfor i in range(m):\n if need[a[i]] not in d:\n d[need[a[i]]]=a[i]\n else:\n if a[i]>d[need[a[i]]]:\n d[need[a[i]]]=a[i]\nd=list(d.items())\nd.sort()\nm=len(d)\ndp=[[0]*10 for _ in range(n+1)]\nfor i in range(n+1):\n for j in range(m):\n if i-d[j][0]>=0:\n if dp[i][0]==dp[i-d[j][0]][0]+1:\n ok=False\n for k in reversed(range(1,10)):\n if k==d[j][1]:\n if dp[i][k]<dp[i-d[j][0]][k]+1:\n ok=True\n break\n elif dp[i][k]>dp[i-d[j][0]][k]+1:\n break\n else:\n if dp[i][k]<dp[i-d[j][0]][k]:\n ok=True\n break\n elif dp[i][k]>dp[i-d[j][0]][k]:\n break\n if ok:\n for k in range(10):\n dp[i][k]=dp[i-d[j][0]][k]\n dp[i][d[j][1]]+=1\n dp[i][0]+=1\n elif dp[i][0]<dp[i-d[j][0]][0]+1:\n for k in range(10):\n dp[i][k]=dp[i-d[j][0]][k]\n dp[i][d[j][1]]+=1\n dp[i][0]+=1\nans=str()\nfor i in reversed(range(1,10)):\n ans+=str(i)*dp[-1][i]\nprint(ans)\n#print(d)\n#print(dp[-1])', 'import sys\ninput=sys.stdin.readline\nn,m=map(int,input().split())\na=list(map(int,input().split()))\nd=dict()\nneed=[0,2,5,5,4,5,6,3,7,6]\nfor i in range(m):\n if need[a[i]] not in d:\n d[need[a[i]]]=a[i]\n else:\n if a[i]>d[need[a[i]]]:\n d[need[a[i]]]=a[i]\nd=list(d.items())\nd.sort()\nm=len(d)\ndp=[[-1]*10 for _ in range(n+1)]\ndp[0]=[0]*10\nfor i in range(n+1):\n for j in range(m):\n if i-d[j][0]>=0 and dp[i-d[j][0]][0]!=-1:\n if dp[i][0]==dp[i-d[j][0]][0]+1:\n ok=False\n for k in reversed(range(1,10)):\n if k==d[j][1]:\n if dp[i][k]<dp[i-d[j][0]][k]+1:\n ok=True\n break\n if dp[i][k]>dp[i-d[j][0]][k]+1:\n break\n else:\n if dp[i][k]<dp[i-d[j][0]][k]:\n ok=True\n break\n if dp[i][k]>dp[i-d[j][0]][k]:\n break\n if ok:\n for k in range(10):\n dp[i][k]=dp[i-d[j][0]][k]\n dp[i][d[j][1]]+=1\n dp[i][0]+=1\n elif dp[i][0]<dp[i-d[j][0]][0]+1:\n for k in range(10):\n dp[i][k]=dp[i-d[j][0]][k]\n dp[i][d[j][1]]+=1\n dp[i][0]+=1\nans=str()\nfor i in reversed(range(1,10)):\n ans+=str(i)*dp[-1][i]\nprint(ans)\n#print(d)\n#print(dp[-1])'] | ['Wrong Answer', 'Accepted'] | ['s998242870', 's077506914'] | [5324.0, 5324.0] | [135.0, 147.0] | [1504, 1539] |
p03128 | u170077602 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\ninput = sys.stdin.readline\n\n#import fractions #fractions.gcd() python~3.4\nsys.setrecursionlimit(1000000)\n\nN, M = map(int,input().split())\nA = list(map(int, input().split()))\nINF = 1e+10\ndef f(x):\n if x == 1:\n return 2\n if x == 2:\n return 5\n if x == 3:\n return 5\n if x == 4:\n return 4\n if x == 5:\n return 5\n if x == 6:\n return 6\n if x == 7:\n return 3\n if x == 8:\n return 7 \n if x == 9:\n return 6\n\nA.sort(reverse=True)\n\ndp=[-INF]*(N+1)\ndp[0] = 0\nfor i in range(1,N+1):\n for j in range(M):\n if i-f(A[j]) >= 0:\n dp[i] = max(dp[i],dp[i-f(A[j])]+1)\n \nans = ""\nremain = dp[N]\nmatch = N\n\nwhile match > 0:\n for i in range(M):\n if match - f(A[i]) > 0 and dp[match - f(A[i])] == remain - 1:\n ans += str(A[i])\n match -= f(A[i])\n remain -= 1\n \n break\n \nprint(ans)\n\n', 'import sys\ninput = sys.stdin.readline\n\n#import fractions #fractions.gcd() python~3.4\nsys.setrecursionlimit(1000000)\n\nN, M = map(int,input().split())\nA = list(map(int, input().split()))\nINF = 1e+10\ndef f(x):\n if x == 1:\n return 2\n if x == 2:\n return 5\n if x == 3:\n return 5\n if x == 4:\n return 4\n if x == 5:\n return 5\n if x == 6:\n return 6\n if x == 7:\n return 3\n if x == 8:\n return 7 \n if x == 9:\n return 6\n\nA.sort(reverse=True)\n\ndp=[-INF]*(N+1)\ndp[0] = 0\nfor i in range(1,N+1):\n for j in range(M):\n if i-f(A[j]) >= 0:\n dp[i] = max(dp[i],dp[i-f(A[j])]+1)\n \nans = ""\nremain = dp[N]\nmatch = N\n\nwhile match > 0:\n for i in range(M):\n if match - f(A[i]) >0 and dp[match - f(A[i])] == remain - 1:\n ans += str(A[i])\n match -= f(A[i])\n remain -= 1\n \n break\n \nprint(ans)\n\n', 'import sys\ninput = sys.stdin.readline\n\n#import fractions #fractions.gcd() python~3.4\nsys.setrecursionlimit(1000000)\n\nN, M = map(int,input().split())\nA = list(map(int, input().split()))\nINF = 1e+10\ndef f(x):\n if x == 1:\n return 2\n if x == 2:\n return 5\n if x == 3:\n return 5\n if x == 4:\n return 4\n if x == 5:\n return 5\n if x == 6:\n return 6\n if x == 7:\n return 3\n if x == 8:\n return 7 \n if x == 9:\n return 6\n\nA.sort(reverse=True)\n\ndp=[-INF]*(N+1)\ndp[0] = 0\nfor i in range(1,N+1):\n for j in range(M):\n if i-f(A[j]) >= 0:\n dp[i] = max(dp[i],dp[i-f(A[j])]+1)\n \nans = ""\nremain = dp[N]\nmatch = N\n\nwhile match > 0:\n for i in range(M):\n if match - f(A[i]) >=0 and dp[match - f(A[i])] == remain - 1:\n ans += str(A[i])\n match -= f(A[i])\n remain -= 1\n \n break\n \nprint(ans)\n\n'] | ['Time Limit Exceeded', 'Time Limit Exceeded', 'Accepted'] | ['s755518337', 's860509644', 's207266238'] | [3308.0, 3308.0, 3424.0] | [2104.0, 2104.0, 138.0] | [950, 949, 950] |
p03128 | u171366497 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["N,M=map(int,input().split())\nA=list(map(int,input().split()))\nmatch=[0,2,5,5,4,5,6,3,7,6]\nmake=dict()\nfor a in A:\n make[a]=match[a]\ndp=[-1]*(N+1)\ndp[0]=0\nfor k in range(1,1+N):\n for d,m in make.items():\n if k-m<0 or dp[k-m]==-1:continue\n dp[k]=max(dp[k],dp[k-m]+1)\n \nans=''\nnow=N\nif \nfor k in range(dp[N]):\n res=(0,0)\n for d,m in make.items():\n if now-m<0:continue\n if dp[now-m]+1==dp[now] and res[0]<d:\n res=(d,m)\n ans+=str(res[0])\n now-=res[1]\nprint(int(ans))", 'N,M=map(int,input().split())\nA=list(map(int,input().split()))\nA.sort(reverse=True)\nuse=[0,2,5,5,4,5,6,3,7,6]\ndp=[-1]*(N+1)\ndp[0]=0\nfor i in range(N+1):\n for k in A:\n if i+use[k]<=N:\n dp[i+use[k]]=max(dp[i]+1,dp[i+use[k]])\nans=""\nnow=N\nfor i in range(dp[N]):\n for k in A:\n if now-use[k]>=0:\n if dp[now-use[k]]==dp[now]-1:\n ans+=str(k)\n now-=use[k]\n break\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s908761504', 's683501858'] | [3064.0, 3416.0] | [17.0, 95.0] | [525, 451] |
p03128 | u174394352 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["d=[0,2,5,5,4,5,6,3,7,6]\nN,M=map(int,input().split())\nA=list(map(int,input().split()))\nl=[]\nfor a in A:\n l.append([a,d[a]])\nl.sort(key=lambda x:x[0],reverse=True)\nl.sort(key=lambda x:x[1])\nmin_val,min_match=l[0]\n\nans=[]\nif N%min_match==0:\n ans.append(int(str(min_val)*(N//min_match)))\nfrom itertools import combinations_with_replacement\nfor i in range(1,M):\n f = False\n r = 1\n while not f:\n for p in combinations_with_replacement(l[1:],r):\n v=[]\n m_sum=0\n for val,mat in p:\n v.append(str(val))\n m_sum+=mat\n if (N-m_sum)%min_match==0:\n ans.append(int(''.join(sorted(v+\n [str(min_val)]*((N-m_sum)//min_match),reverse=True))))\n f = (len(ans) == 0)\n r += 1\nprint(max(ans))\n\n", "d=[0,2,5,5,4,5,6,3,7,6]\nN,M=map(int,input().split())\nA=list(map(int,input().split()))\n\ndp = [-1 for i in range(N+1)]\ndp[0] = 0\n\n\nfor i in range(1,N+1):\n tmp = -1\n for a in A:\n if i-d[a]>=0 and dp[i-d[a]] != -1:\n tmp = max(tmp,dp[i-d[a]]+1)\n dp[i] = tmp\n\n\nA.sort(reverse=True)\nans = ''\nwhile N>0:\n for a in A:\n if N-d[a]>=0 and dp[N-d[a]] == dp[N]-1:\n ans += str(a)\n N -= d[a]\n break\nprint(ans)\n\n\n\n"] | ['Runtime Error', 'Accepted'] | ['s491710907', 's361560783'] | [3064.0, 3320.0] | [17.0, 90.0] | [781, 467] |
p03128 | u175743386 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['dic = {\n 1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6\n}\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA = sorted(A, reverse=True)\ndic2 = {}\nfor i in A:\n try:\n dic2[dic[i]]\n except:\n dic2[dic[i]] = i \nresult_list = []\nitems = sorted(dic2.items())\nwhile True:\n if len(items) == 0:\n break\n else:\n if N >= items[0]:\n result_list.append(items[1])\n N = N - items[0]\n else:\n items.pop(0)\nreturn sorted(result_list, reverse=True)\n ', 'N,M = map(int,input().split())\nA = list(map(int,input().split()))\n \ndp = [-1 for i in range(N+10)]\nl = [0,2,5,5,4,5,6,3,7,6]\ndp[0] = 0\nfor i in range(N-1):\n for s in A:\n if dp[i] == -1 and i!=0:\n continue\n if dp[i + l[s]] < dp[i]*10+s:\n dp[i + l[s]] = dp[i]*10+s\nprint(dp[N])'] | ['Runtime Error', 'Accepted'] | ['s352488391', 's064144668'] | [3064.0, 14668.0] | [17.0, 229.0] | [515, 314] |
p03128 | u179169725 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['\n\n\n\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nA.sort(reverse=True) \n\n\nnum = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n\n\n\ndp = [-1 * float("inf")] * (N + 1)\n\n\ndp[0] = 0\nfor a in A:\n if num[a] <= N: \n dp[num[a]] = 1\n\n\nfor i in range(1, N + 1): \n for a in A: \n if i - num[a] >= 0: \n \n dp[i] = max(dp[i], dp[i - num[a]] + 1)\n\n\n\nans = ""\nfor i in range(dp[N]): \n for a in A: \n \n if N - num[a]\u3000> -1 and dp[N - num[a]] == dp[N] - 1:\n ans += str(a)\n N -= num[a] \n break\n\nprint(ans)\n', '\n\n\n\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nA.sort(reverse=True) \n\n\nnum = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n\n\n\ndp = [-1 * float("inf")] * (N + 1)\n\n\ndp[0] = 0\nfor a in A:\n if num[a] <= N: \n dp[num[a]] = 1\n\n\nfor i in range(1, N + 1): \n for a in A: \n if i - num[a] >= 0: \n \n dp[i] = max(dp[i], dp[i - num[a]] + 1)\n\n\n\nans = ""\nfor i in range(dp[N]): \n for a in A: \n \n if N - num[a] > -1 and dp[N - num[a]] == dp[N] - 1:\n ans += str(a)\n N -= num[a] \n break\n\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s846470173', 's453351862'] | [3064.0, 3308.0] | [18.0, 89.0] | [2030, 2028] |
p03128 | u181526702 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nB = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)\na_min, n_min = min(B, key=lambda x: x[1])\ng = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]\nl = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]\nl.sort(key=lambda x: x[1], reverse=True)\n\n\ndef dp(rem, C):\n ret = None\n if rem == 0:\n ret = []\n elif rem > 0:\n for a, m in C:\n nxt = dp(rem-m, C)\n if nxt is not None:\n ret = [a] + nxt\n break\n C.pop(0)\n return ret\n\n\nlst = dp(N % n_min, g + l)\nlst = sorted(lst + [a_min] * (N//n_min - len(lst)), reverse=True)\nprint(''.join(map(str, lst)))", 'from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nnum = sorted([(a, req[a]) for a in A], key=lambda x: x[1])\nk_min, n_min = num[0]\ngt = sorted([(k, n-n_min) for k, n in num[1:] if k > k_min],\n key=lambda x: x[0], reverse=True)\nlt = sorted([(k, n-n_min) for k, n in num[1:] if k < k_min],\n key=lambda x: x[0])\norder = N // n_min\nsum_rem = N - n_min*order\n\nlst = []\nfor k, n in gt:\n m = sum_rem // n\n lst.extend([k]*m)\n sum_rem -= n*m\nfor k, n in lt:\n m = sum_rem // n\n lst.extend([k]*m)\n sum_rem -= n*m\nlst.extend([k_min]*(order-len(lst)))', "from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nB = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)\nmin_ = min(B, key=lambda x: x[1])\n\n\ndef dp(N, B, min_):\n if N == 0:\n return []\n elif N // min_[1] < 1:\n return None\n elif N % min_[1] == 0:\n return [min_[0]] * (N // min_[1])\n else:\n for a, n in B:\n if (N // min_[1]) - ((N-n) // min_[1]) == 1:\n ret = dp(N-n, B, min_[1])\n if ret is not None:\n return [a] + ret\n\n\nlst = dp(N, B, min_)\nprint(''.join(map(str, lst)))", "from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nB = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)\na_min, n_min = min(B, key=lambda x: x[1])\ng = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]\nl = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]\nl.sort(key=lambda x: x[1], reverse=True)\n\ndef dp(rem, C):\n ret = None\n if rem == 0:\n ret = []\n elif rem > 0:\n for a, m in C:\n nxt = dp(rem-m, C)\n if nxt is not None:\n ret = [a] + nxt\n break\n return ret\n\n\nlst = dp(N % n_min, g + l)\nprint(''.join(map(str, lst)))", "from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nnum = {a: req[a] for a in A}\nnum_min = min(num.items(), key=lambda x: x[1])\nrem = sorted([(k, n-num_min[1]) for k, n in num.items()], reverse=True)\norder = N // num_min[1]\nsum_rem = N - num_min[1]*order\n\ns = ''\nfor _ in range(order):\n if sum_rem:\n for k, n in rem:\n if sum_rem >= n:\n s += str(k)\n sum_rem -= n\n break\n else:\n s += str(num_min[0])\n\nprint(s)", "from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nB = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)\na_min, n_min = min(B, key=lambda x: x[1])\ng = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]\nl = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]\nl.sort(key=lambda x: x[1], reverse=True)\nC = g + l\n\ndef dp(rem, C):\n ret = None\n if rem == 0:\n ret = []\n elif rem > 0:\n for i in range(len(C)):\n a, m = C[i]\n nxt = dp(rem-m, C[i:])\n if nxt is not None:\n ret = [a] + nxt\n break\n return ret\n\n\ni = 0\nwhile True:\n quo = N // n_min - i\n rem = N % n_min + i * n_min\n lst = dp(rem, C)\n if lst is not None:\n lst = sorted(lst + [a_min] * quo, reverse=True)\n print(''.join(map(str, lst)))\n break", "from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nB = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)\na_min, n_min = min(B, key=lambda x: x[1])\ng = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]\nl = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]\nl.sort(key=lambda x: x[1], reverse=True)\n\nlst = []\nlst = sorted(lst + [a_min] * (N//n_min - len(lst)), reverse=True)\nprint(''.join(map(str, lst)))", "from sys import stdin\n\nN, *A = map(int, stdin.read().split())\n\nA_min = min(A)\n\nk = 1\nfor i in range(int(A_min**0.5))[::-1]:\n if A_min % (i+1) != 0:\n continue\n k1, k2 = i+1, A_min//(i+1)\n if all(a % k2 == 0 for a in A):\n k = max(k, k2)\n elif all(a % k1 == 0 for a in A):\n k = max(k, k1)\n\nprint(k)\n\n# D\n\nfrom sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nnum = sorted([(a, req[a]) for a in A], key=lambda x: x[1])\nk_min, n_min = num[0]\ngt = sorted([(k, n-n_min) for k, n in num[1:] if k > k_min],\n key=lambda x: x[0], reverse=True)\nlt = sorted([(k, n-n_min) for k, n in num[1:] if k < k_min],\n key=lambda x: x[0])\norder = N // n_min\nsum_rem = N - n_min*order\n\nlst = []\nfor k, n in gt:\n m = sum_rem // n\n lst.extend([k]*m)\n sum_rem -= n*m\nfor k, n in lt:\n m = sum_rem // n\n lst.extend([k]*m)\n sum_rem -= n*m\nlst.extend([k_min]*(order-len(lst)))\n\n\nprint(''.join(map(str, sorted(lst, reverse=True))))", "from sys import stdin\n\nN, M, *A = map(int, stdin.read().split())\nreq = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nB = sorted([(a, req[a]) for a in A], key=lambda x: x[0], reverse=True)\na_min, n_min = min(B, key=lambda x: x[1])\ng = [(a, n-n_min) for a, n in B if a > a_min and n > n_min]\nl = [(a, n-n_min) for a, n in B if a < a_min and n > n_min]\nl.sort(key=lambda x: x[1], reverse=True)\nC = g + l\n\ndef dp(rem, C):\n ret = None\n if rem == 0:\n ret = []\n elif rem > 0:\n for i in range(len(C)):\n a, m = C[i]\n nxt = dp(rem-m, C[i:])\n if nxt is not None:\n ret = [a] + nxt\n break\n return ret\n\n\ni = 0\nwhile True:\n quo = N // n_min - i\n rem = N % n_min + i * n_min\n lst = dp(rem, C)\n if lst is not None:\n lst = sorted(lst + [a_min] * (quo-len(lst)), reverse=True)\n print(''.join(map(str, lst)))\n break\n i += 1"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s020767769', 's427173892', 's651266219', 's687599756', 's796298682', 's839328393', 's900163927', 's969036244', 's587413984'] | [3316.0, 3064.0, 3316.0, 3064.0, 3064.0, 3316.0, 3316.0, 3188.0, 3316.0] | [19.0, 17.0, 19.0, 20.0, 21.0, 2104.0, 19.0, 17.0, 19.0] | [842, 711, 716, 754, 614, 972, 562, 1100, 994] |
p03128 | u188745744 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N,M=map(int,input().split())\nl=list(map(int,input().split()))\nw=[2,5,5,4,5,6,3,7,6]\ndp=[0]*(N+1)\nfor i in range(N):\n for j in l:\n if w[j-1]+i<=N:\n dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j)\nprint(dp[N])', 'N,M=map(int,input().split())\nl=list(map(int,input().split()))\nw=[2,5,5,4,5,6,3,7,6]\nl.sort()\ndp=[0]*(max(N+1,8))\nfor j in l:\n dp[w[j-1]]=j\nfor i in range(N):\n if dp[i]!=0:\n for j in l:\n if w[j-1]+i<=N:\n dp[i+w[j-1]]=max(dp[i+w[j-1]],dp[i]*10+j)\nprint(dp[N])'] | ['Wrong Answer', 'Accepted'] | ['s278391928', 's203743366'] | [20376.0, 20480.0] | [135.0, 134.0] | [216, 285] |
p03128 | u189479417 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int,input().split())\nA = list(map(int,input().split()))\nA.sort(reverse = True)\nd = [0,2,5,5,4,5,6,3,7,6]\nS = set()\nfor a in A:\n S.add(d[a])\n\nINF = 10 ** 8\ndp = [-INF for _ in range(N+1)]\ndp[0] = 0\n\nfor i in range(N+1):\n for s in S:\n if i - s >= 0:\n dp[i] = max(dp[i], dp[i-s]+1)\n\nans = 0\ndigit = dp[N]\n\nprint(dp)\n\nfor i in range(digit-1, -1, -1):\n if i != 0:\n for a in A:\n if dp[N-d[a]] == i:\n ans = ans * 10 + a\n N -= d[a]\n break\n else:\n for a in A:\n if N == d[a]:\n ans = ans * 10 + a\n break\nprint(ans)', 'N, M = map(int,input().split())\nA = list(map(int,input().split()))\nA.sort(reverse = True)\nd = [0,2,5,5,4,5,6,3,7,6]\nS = set()\nfor a in A:\n S.add(d[a])\n\nINF = 10 ** 8\ndp = [-INF for _ in range(N+1)]\ndp[0] = 0\n\nfor i in range(N+1):\n for s in S:\n if i - s >= 0:\n dp[i] = max(dp[i], dp[i-s]+1)\n\nans = 0\ndigit = dp[N]\n\nfor i in range(digit-1, -1, -1):\n if i != 0:\n for a in A:\n if dp[N-d[a]] == i:\n ans = ans * 10 + a\n N -= d[a]\n break\n else:\n for a in A:\n if N == d[a]:\n ans = ans * 10 + a\n break\nprint(ans)'] | ['Wrong Answer', 'Accepted'] | ['s753739225', 's775205157'] | [3572.0, 3444.0] | [61.0, 65.0] | [655, 644] |
p03128 | u190185531 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import math\nimport copy\nimport bisect\n\n\n\n\n\n\n\ndef nCast(number):\n if type(number)==str:\n return int(number)\n for idx in range(0,len(number)):\n if type(number[idx])==str:\n\n number[idx]=int(number[idx])\n else:\n nCast(number[idx])\n return number\n \ndef inputArr(w):\n l=list()\n for idx in range(0,w):\n l.append(input())\n return l\ndef inputArr1(w):\n l=list()\n for idx in range(0,w):\n l.append(input().split())\n return l\n\nn=nCast(input().split())\nm=nCast(input().split())\n\ndef cmp(l1,l2):\n\n if len(l1)!=len(l2):\n return len(l1)-len(l2)\n for idx in range(0,len(l1)):\n if l1[idx]!=l2[idx]:\n return l1[idx]-l2[idx]\n return 0\ndef func():\n l=list()\n nn=[1,2,3,4,5,6,7,8,9]\n s=set(m)\n mm=[2,5,5,4,5,6,3,7,6]\n d=dict()\n for idx in nn:\n if idx in s:\n d[nn[idx-1]]=mm[idx-1]\n for idx in range(0,n[0]+1):\n l.append(list())\n for idx in range(1,n[0]+1):\n for idy in d:\n if idx-d[idy]==0:\n max=0\n for dd in d:\n if d[dd]==idx and dd>max:\n max=dd\n if cmp([max],l[idx])>0:\n l[idx]=[max]\n if idx-d[idy]>0:\n tmp=l[idx-d[idy]]\n if len(tmp)==0:\n continue\n tmp.append(idy)\n #tmp.sort(reverse=True)\n if cmp(tmp,l[idx])>0:\n l[idx]=tmp\n\n result=""\n l[-1].sort(reverse=True)\n for idx in range(0,len(l[-1])):\n result=result+str(l[-1][idx])\n return result\n\n\n\nprint(func()) \n\n', 'import math\nimport copy\nimport bisect\n\n\n\n\n\n\n\ndef nCast(number):\n if type(number)==str:\n return int(number)\n for idx in range(0,len(number)):\n if type(number[idx])==str:\n\n number[idx]=int(number[idx])\n else:\n nCast(number[idx])\n return number\n \ndef inputArr(w):\n l=list()\n for idx in range(0,w):\n l.append(input())\n return l\ndef inputArr1(w):\n l=list()\n for idx in range(0,w):\n l.append(input().split())\n return l\n\nn=nCast(input().split())\nm=nCast(input().split())\n\ndef cmp(l1,l2):\n\n if len(l1)!=len(l2):\n return len(l1)-len(l2)\n for idx in range(len(l1)-1,0,-1):\n if l1[idx]!=l2[idx]:\n return l1[idx]-l2[idx]\n return 0\ndef func():\n l=list()\n nn=[1,2,3,4,5,6,7,8,9]\n s=set(m)\n mm=[2,5,5,4,5,6,3,7,6]\n d=dict()\n for idx in nn:\n if idx in s:\n if idx==2 and 5 in s:\n continue\n if idx==3 and 5 in s:\n continue\n if idx==2 and 3 in s:\n continue\n if idx==6 and 9 in s:\n continue\n d[nn[idx-1]]=mm[idx-1]\n for idx in range(0,n[0]+1):\n l.append(list())\n for idx in range(1,n[0]+1):\n for idy in d:\n if idx-d[idy]>0:\n tmp=l[idx-d[idy]][:]\n if len(tmp)==0:\n continue\n tmp.append(idy)\n #tmp.sort(reverse=True)\n if cmp(tmp,l[idx])>0:\n l[idx]=tmp\n elif idx-d[idy]==0:\n max=0\n for dd in d:\n if d[dd]==idx and dd>max:\n max=dd\n if cmp([max],l[idx])>0:\n l[idx]=[max]\n\n result=""\n l[-1].sort(reverse=True)\n for idx in range(0,len(l[-1])):\n result=result+str(l[-1][idx])\n return result\n\n\n\nprint(func()) \n\n'] | ['Wrong Answer', 'Accepted'] | ['s728188626', 's750706175'] | [4328.0, 285288.0] | [2104.0, 1091.0] | [1677, 1923] |
p03128 | u197300773 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\n elif p[i][0]>-1 and sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(430)]\np[0]=[0 for j in range(M)]\nfor i in range(10):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>=sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\nfor j in range(M):\n if x[j]==min(x): Mi=j\n\nans=[0 for i in range(M)]\nfor i in range(420):\n if N-i<0: break\n if (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>sum(ans):\n ans=p[i]\n ans[Mi]+=(N-i)//x[Mi]\n\nfor i in range(M-1,-1,-1):\n for j in range(ans[i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n ip=i+x[j]\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[ip][k] :\n p[ip]=[tmp[l] for l in range(M)]\n break\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n elif sum(p[i])+1==sum(p[i+x[j]]) and chk(i,j):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(430)]\np[0]=[0 for j in range(M)]\n\nfor i in range(421):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\n elif p[i][0]>-1 and sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\nfor j in range(M):\n if x[j]==min(x): Mi=j\n\nans=[0 for i in range(M)]\nfor i in range(421):\n if N-i<0: break\n if (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>=sum(ans):\n ans=p[i]\n ans[Mi]+=(N-i)//x[Mi]\n\nfor i in range(M-1,-1,-1):\n for j in range(ans[i]):\n print(a[i],end="")', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\np=[[-1 for j in range(M)] for i in range(430)]\np[0]=[0 for j in range(M)]\n\nfor i in range(10):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\nfor j in range(M):\n if x[j]==min(x): Mi=j\n\nans=[0 for i in range(M)]\nfor i in range(420):\n if N-i<0: break\n if (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>sum(ans):\n ans=p[i]\n ans[Mi]+=(N-i)//x[Mi]\n\nfor i in range(M-1,-1,-1):\n for j in range(ans[i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n for j in range(M-1,-1,-1):\n if p[i][0]>-1:\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M-1,-1,-1):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\nans=""\nwhile N>0:\n for j in range(M-1,-1,-1):\n if sum(p[N])==sum(p[N-x[j]])+1:\n ans+=str(a[j])\n N-=x[j]\n break\nprint(ans[::-1])\n\n\n', 'import sys\n\ndef chk(i,j):\n tmp=[]\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n elif sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'def chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if p[i][0]>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M-1,-1,-1):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\np=[-100 for i in range(N+10)]\np[0]=0\nfor i in range(N):\n if p[i]>-1:\n for j in range(M):\n p[i+x[j]]=max(p[i+x[j]],p[i]+1)\n\nans=""\nwhile N>0:\n for j in range(M-1,-1,-1):\n if p[N]==p[N-x[j]]+1:\n ans+=str(a[j])\n N-=x[j]\n break\nprint(ans[::-1])\n\n\n', 'import sys\n\ndef chk(i,j):\n ip=i+x[j]\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[ip][k] :\n p[ip]=[tmp[l] for l in range(M)]\n return\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n \n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=tmp[j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M-1,-1,-1):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i+x[j]][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'import sys\n \ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n \nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n \na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n \n \n \np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n \nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n \n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n \n \nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'def chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+100)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+10):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'def chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(430)]\np[0]=[0 for j in range(M)]\n\nfor i in range(421):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\n elif p[i][0]>-1 and sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\nfor j in range(M):\n if x[j]==min(x): Mi=j\n\nans=[0 for i in range(M)]\nfor i in range(420):\n if N-i<0: break\n if (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>sum(ans):\n ans=p[i]\n ans[Mi]+=(N-i)//x[Mi]\n\nfor i in range(M-1,-1,-1):\n for j in range(ans[i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[]\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] : return 1\n \n return 0\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n elif sum(p[i])+1==sum(p[i+x[j]]) and chk(i,j):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'import sys\n\ndef chk(i,j):\n ip=i+x[j]\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[ip][k] :\n p[ip]=[tmp[l] for l in range(M)]\n return\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n elif sum(p[i])+1==sum(p[i+x[j]]) and chk(i,j):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\n elif p[i][0]>-1 and sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1) and tmp!=p[i+x[j]]:\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\n elif p[i][0]>-1 and sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n if tmp!=p[i+x[j]]:\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M-1,-1,-1):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'import sys\n\ndef chk(i,j):\n tmp=[]\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[l] for l in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n \n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n \np=[[-1 for j in range(M)] for i in range(430)]\np[0]=[0 for j in range(M)]\nfor i in range(420):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>=sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n \nfor j in range(M):\n if x[j]==min(x): Mi=j\n \nans=[0 for i in range(M)]\nfor i in range(420):\n if N-i<0: break\n if (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>sum(ans):\n ans=p[i]\n ans[Mi]+=(N-i)//x[Mi]\n \nfor i in range(M-1,-1,-1):\n for j in range(ans[i]):\n print(a[i],end="")', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(430)]\np[0]=[0 for j in range(M)]\n\nfor i in range(421):\n for j in range(M):\n if p[i][0]>-1 and sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[p[i][k] for k in range(M)]\n p[i+x[j]][j]+=1\n\n elif p[i][0]>-1 and sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\nfor j in range(M):\n if x[j]==min(x): Mi=j\n\nans=[0 for i in range(M)]\n\nfor i in range(421):\n if N-i<0: break\n\n if (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>sum(ans):\n ans=[p[i][k] for k in range(M)]\n ans[Mi]+=(N-i)//x[Mi]\n\n elif (N-i)%x[Mi]==0 and (N-i)//x[Mi]+sum(p[i])>sum(ans):\n tmp=[p[i][k] for k in range(M)]\n tmp[Mi]+=(N-i)//x[Mi]\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i][k] :\n ans=[tmp[k] for k in range(M)]\n break\n\n\nfor i in range(M-1,-1,-1):\n for j in range(ans[i]):\n print(a[i],end="")', 'N,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nx=[ x[a[i]] for i in range(M) ]\n\np=[[-1 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n for j in range(M):\n if p[i][0]>-1:\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]]=[ p[i][k] for k in range(M) ]\n p[i+x[j]][j]+=1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]+=1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n break\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\nprint("a:",a)\nprint("x:",x)\n\n\np=[-100 for i in range(N+10)]\np[0]=0\nfor i in range(N):\n if p[i]>-1:\n for j in range(M):\n p[i+x[j]]=max(p[i+x[j]],p[i]+1)\n\nans=""\nwhile N>0:\n for j in range(M-1,-1,-1):\n if p[N]==p[N-x[j]]+1:\n ans+=str(a[j])\n N-=x[j]\n break\nprint(ans)\n\n\n', 'import sys\n\ndef func():\n for i in range(N//x[a[0]]):\n print(a[0],end="")\n sys.exit()\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\n\nif M==1: func()\n\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100]*M for i in range(N+100)]\np[0]=[0]*M\n\nfor i in range(N+10):\n if sum(p[i])>-1:\n for j in range(M):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n return\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\n\n\np=[[-100 for j in range(M)] for i in range(N+10)]\np[0]=[0 for j in range(M)]\n\nfor i in range(N+1):\n if sum(p[i])>-1:\n for j in range(M-1,-1,-1):\n if sum(p[i])+1>sum(p[i+x[j]]):\n p[i+x[j]] = [ p[i][k] for k in range(M) ]\n p[i+x[j]][j]=p[i][j]+1\n\n elif sum(p[i])+1==sum(p[i+x[j]]):\n chk(i,j)\n\n\nfor i in range(M-1,-1,-1):\n for j in range(p[N][i]):\n print(a[i],end="")\n', 'import sys\n\ndef chk(i,j):\n tmp=[p[i][k] for k in range(M)]\n tmp[j]=p[i][j]+1\n for k in range(M-1,-1,-1):\n if tmp[k] > p[i+x[j]][k] :\n p[i+x[j]]=[tmp[k] for k in range(M)]\n\nN,M=map(int,input().split())\nx=[0,2,5,5,4,5,6,3,7,6]\na=list(map(int,input().split()))\na.sort()\nb=[]\nfor i in range(M):\n for j in range(M):\n if x[a[j]]==x[a[i]]: tmp=j\n b.append(a[tmp]) \n\na=list(set(b))\na.sort()\nM=len(a)\nx=[ x[a[i]] for i in range(M) ]\n\np=[-100 for i in range(N+10)]\np[0]=0\nfor i in range(N):\n if p[i]>-1:\n for j in range(M):\n p[i+x[j]]=max(p[i+x[j]],p[i]+1)\n\nans=""\nwhile N>0:\n for j in range(M-1,-1,-1):\n if p[N]==p[N-x[j]]+1:\n ans+=str(a[j])\n N-=x[j]\n break\nprint(ans)\n\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s043474771', 's105314488', 's115222748', 's167904041', 's222073270', 's243752927', 's275889057', 's285673849', 's296855449', 's332610481', 's377417749', 's442477267', 's462536288', 's495054585', 's530945983', 's585024521', 's620683287', 's637001698', 's644372733', 's673069737', 's717475243', 's717995963', 's725354210', 's744842966', 's831911747', 's843595478', 's847061714', 's892506510', 's911903144', 's959769372', 's990976417', 's995842290', 's193861509'] | [6120.0, 3956.0, 5512.0, 4084.0, 3956.0, 5544.0, 5492.0, 6196.0, 4648.0, 5512.0, 6132.0, 5544.0, 3436.0, 5512.0, 5520.0, 5544.0, 5572.0, 6128.0, 5572.0, 4084.0, 5544.0, 5512.0, 5108.0, 6144.0, 5572.0, 5544.0, 3956.0, 4084.0, 6120.0, 3436.0, 5572.0, 5544.0, 3436.0] | [435.0, 24.0, 211.0, 41.0, 24.0, 219.0, 237.0, 422.0, 254.0, 225.0, 420.0, 224.0, 69.0, 216.0, 218.0, 213.0, 226.0, 406.0, 238.0, 40.0, 235.0, 220.0, 29.0, 434.0, 221.0, 227.0, 32.0, 40.0, 415.0, 66.0, 230.0, 219.0, 70.0] | [755, 680, 1027, 972, 679, 910, 916, 797, 1008, 929, 757, 919, 772, 961, 942, 939, 917, 760, 927, 971, 992, 1039, 772, 800, 936, 938, 685, 1267, 788, 795, 1002, 938, 766] |
p03128 | u198440493 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["n, m = map(int, input().split(' '))\na = list(map(int, input().split(' ')))\na = sorted(a, reverse=True)\nl = [2, 5, 5, 4, 5, 6, 3, 7, 6]\n_min = 10\nind = 10\nfor x in a:\n _ind = x-1\n if l[_ind] < _min:\n _min = l[_ind]\n ind = x\n \nl = list(map(lambda x: x-_min, l))\nmod = n % _min\nk = n // _min\nans = str()\nfor i in range(k):\n for x in a:\n _ind = x-1\n if not l[_ind]:\n continue\n else:\n _mod = mod - l[_ind]\n if _mod >= 0:\n mod = _mod\n ans += str(x)\n break\n else:\n continue\n if mod <=0:\n break\nans += str(ind)*(k - len(ans))\nprint(int(ans))", "n, m = map(int, input().split(' '))\na = list(map(int, input().split(' ')))\na = sorted(a, reverse=True)\nl = [2, 5, 5, 4, 5, 6, 3, 7, 6]\n_min = 10\nind = 10\nfor x in a:\n _ind = x-1\n if l[_ind] < _min:\n _min = l[_ind]\n ind = x\n \nl = list(map(lambda x: x-_min, l))\nmod = n % _min\nk = n // _min\nans = str()\nfor i in range(k):\n for x in a:\n _ind = x-1\n if not l[_ind]:\n continue\n else:\n _mod = mod - l[_ind]\n if _mod >= 0:\n mod = _mod\n ans += str(x)\n break\n else:\n continue\nans += str(ind)*(k - len(ans))\nprint(int(ans))", "INF = float('inf')\nn, m = map(int, input().split())\na = list(map(int, input().split()))\ncost = [2, 5, 5, 4, 5, 6, 3, 7, 6]\nl = [[x, cost[x-1]] for x in a]\nl = sorted(l, key = lambda x: x[1]*10-x[0])\nr = l[0]\nk = max(n-200, 0)//r[1]\nn -= r[1]*k\n_max = [0] + [-INF]*n\nfor i in range(1, n+1):\n if 50 < i < n-50:\n _max[i] = max(_max[i], _max[i-r[1]]*10 + r[0])\n else:\n for x in l:\n ind = i-x[1]\n if ind >= 0:\n _max[i] = max(_max[i], _max[ind]*10 + x[0])\nans = str(_max[n])\nans = ans[:10] + str(r[0])*k + ans[10:]\nprint(ans)"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s120283453', 's309230252', 's004718964'] | [3064.0, 3064.0, 3064.0] | [23.0, 31.0, 18.0] | [606, 582, 544] |
p03128 | u201234972 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map( int, input().split())\nA = list( map( int, input().split()))\nC = [0,2,5,5,4,5,6,3,7,6]\ndp = [(0,0)]*(N+1)\nfor a in A:\n dp[C[a]] = (1,0)\nZ = list( set( C[a] for a in A))\nZ.sort()\n', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nC = [0,2,5,5,4,5,6,3,7,6]\ndp = [(0,0)]*(N+1)\nfor a in A:\n dp[C[a]] = (1,0)\n# Z = list( set( [C[a] for a in A]))\n# Z.sort()\n\n\n\n\n# dp[i] = (1, i-z)\n# break\n\n# ANS = [0]*10\n# while s != 0:\n# _, b = dp[s]\n# ANS[s-b] += 1\n\n# ans = ""\n\n# if ANS[C[i]] > 0:\n\n\n# ANS[C[i]] = 0\n# print( ans)', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nC = [0,2,5,5,4,5,6,3,7,6]\ndp = [(0,0)]*(N+1)\nfor a in A:\n dp[C[a]] = (1,0)\nZ = sorted(list( set( C[a] for a in A)))\nfor i in range(2,N+1):\n for z in Z:\n if i >= z:\n if dp[i-z][0] == 1:\n dp[i] = (1, i-z)\n break\n print(dp)\ns = N\nANS = [0]*10\nwhile s != 0:\n _, b = dp[s]\n ANS[s-b] += 1\n if s == b:\n break\n s = b\nans = ""\nfor i in range(9,0,-1):\n if ANS[C[i]] > 0:\n if i in A:\n ans += str(i)*ANS[C[i]]\n ANS[C[i]] = 0\nprint( ans)', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nNeeds = [0,2,5,5,4,5,6,3,7,6]\nA.sort(reverse = True)\nV = [0]*N\nCheck = []\nfor a in A:\n if V[Needs[a]] == 0:\n Check.append(Needs[a])\n V[Needs[a]] = a\nCheck.sort()\ndp = [-100]*(N+1)\ndp[0] = 0\n\nfor x in Check:\n dp[x] = 1\nfor i in range(1,N):\n t = dp[i]\n if x + i <= N:\n if dp[x+i] < t + 1:\n dp[x+i] = t+1\nans = ""\nt = N\nW = [0]*10\nwhile t > 0:\n for x in Check:\n if dp[t-x]+1 == dp[t]:\n W[V[x]] += 1\n t -= x\n break\nfor i in range(9,0,-1):\n ans += str(i)*W[i]\nprint(ans)', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nC = [0,2,5,5,4,5,6,3,7,6]\ndp = [(0,0)]*(N+1)', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nC = [0,2,5,5,4,5,6,3,7,6]\ndp = [(0,0)]*(N+1)\nfor a in A:\n dp[C[a]] = (1,0)\nZ = list( set( C[a] for a in A))\nZ.sort()\nfor i in range(2,N+1):\n for z in Z:\n if i > z:\n if dp[i-z][0] == 1:\n dp[i] = (1, i-z)\n break\nprint("a")\n\n# ANS = [0]*10\n# while s != 0:\n# _, b = dp[s]\n# ANS[s-b] += 1\n\n# ans = ""\n\n# if ANS[C[i]] > 0:\n\n\n# ANS[C[i]] = 0\n# print( ans)\n', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nNeeds = [0,2,5,5,4,5,6,3,7,6]\nA.sort(reverse = True)\nV = [0]*N\nCheck = []\nfor a in A:\n if V[Needs[a]] == 0:\n Check.append(Needs[a])\n V[Needs[a]] = a\nCheck.sort()\ndp = [-100000]*(N+1)\ndp[0] = 0\n\nfor x in Check:\n dp[x] = 1\nfor i in range(1,N):\n t = dp[i]\n if x + i <= N:\n if dp[x+i] < t + 1:\n dp[x+i] = t+1\nans = ""\nt = N\nW = [0]*10\nwhile t > 0:\n for x in Check:\n if dp[t-x]+1 == dp[t]:\n W[V[x]] += 1\n t -= x\n break\nfor i in range(9,0,-1):\n ans += str(i)*W[i]\nprint(ans)', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nNeeds = [0,2,5,5,4,5,6,3,7,6]\nA.sort(reverse = True)\nV = [0]*N\nCheck = []\nfor a in A:\n if V[Needs[a]] == 0:\n Check.append(Needs[a])\n V[Needs[a]] = a\nCheck.sort()\ndp = [-100000]*(N+1)\ndp[0] = 0\n\nfor x in Check:\n dp[x] = 1\nfor i in range(1,N):\n t = dp[i]\n if x + i <= N:\n if dp[x+i] < t + 1:\n dp[x+i] = t+1\nans = ""\nt = N\nW = [0]*10\nwhile t > 0:\n for x in Check:\n if dp[t-x]+1 == dp[t]:\n W[V[x]] += 1\n t -= x\n break\nfor i in range(9,0,-1):\n ans += str(i)*W[i]\nprint(ans)\n', 'N, M = map( int, input().split())\nA = list( map( int, input().split()))\nNeeds = [0,2,5,5,4,5,6,3,7,6]\nA.sort(reverse = True)\nV = [0]*10\nCheck = []\nfor a in A:\n if V[Needs[a]] == 0:\n Check.append(Needs[a])\n V[Needs[a]] = a\nCheck.sort()\ndp = [-100000]*(N+1)\ndp[0] = 0\n\nfor x in Check:\n if x <= N:\n dp[x] = 1\nfor i in range(1,N):\n t = dp[i]\n for x in Check:\n if x + i <= N:\n if dp[x+i] < t + 1:\n dp[x+i] = t+1\nans = ""\nt = N\nW = [0]*10\nwhile t > 0:\n for a in A:\n x = Needs[a]\n if t-x>=0:\n if dp[t-x]+1 == dp[t]:\n W[V[x]] += 1\n t -= x\n break\nfor i in range(9,0,-1):\n ans += str(i)*W[i]\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s083973964', 's089743134', 's330318841', 's396433918', 's443397805', 's697398237', 's818913428', 's852766220', 's110768367'] | [3060.0, 3060.0, 66164.0, 3064.0, 3060.0, 3956.0, 3440.0, 3064.0, 3312.0] | [17.0, 20.0, 2104.0, 17.0, 18.0, 24.0, 2104.0, 18.0, 57.0] | [192, 610, 604, 639, 116, 604, 630, 643, 735] |
p03128 | u201856486 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['# coding: utf-8\nimport sys\n\n\n# import math\n# import itertools\n\n# import numpy as np\n\n\n"""Template"""\n\n\nclass IP:\n \n\n def __init__(self):\n self.input = sys.stdin.readline\n\n def I(self):\n \n return int(self.input())\n\n def S(self):\n \n return self.input()\n\n def IL(self):\n \n return list(map(int, self.input().split()))\n\n def SL(self):\n \n return list(map(str, self.input().split()))\n\n def ILS(self, n):\n \n return [int(self.input()) for _ in range(n)]\n\n def SLS(self, n):\n \n return [self.input() for _ in range(n)]\n\n def SILS(self, n):\n \n return [self.IL() for _ in range(n)]\n\n def SSLS(self, n):\n \n return [self.SL() for _ in range(n)]\n\n\nclass Idea:\n def __init__(self):\n pass\n\n def HF(self, p):\n \n return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))\n\n def Bfs2(self, a):\n \n \n # https://blog.rossywhite.com/2018/08/06/bit-search/\n \n value = []\n for i in range(1 << len(a)):\n output = []\n\n for j in range(len(a)):\n if self.bit_o(i, j):\n \n # output.append(a[j])\n output.append(a[j])\n value.append([format(i, \'b\').zfill(16), sum(output)])\n\n value.sort(key=lambda x: x[1])\n bin = [value[k][0] for k in range(len(value))]\n val = [value[k][1] for k in range(len(value))]\n return bin, val\n\n def S(self, s, r=0, m=-1):\n \n r = bool(r)\n if m == -1:\n s.sort(reverse=r)\n else:\n s.sort(reverse=r, key=lambda x: x[m])\n\n def bit_n(self, a, b):\n \n return bool((a >> b & 1) > 0)\n\n def bit_o(self, a, b):\n \n return bool(((a >> b) & 1) == 1)\n\n def ceil(self, x, y):\n \n return -(-x // y)\n\n def ave(self, a):\n \n return sum(a) / len(a)\n\n def gcd(self, x, y):\n if y == 0:\n return x\n else:\n return self.gcd(y, x % y)\n\n\n\n\n\ndef main():\n \n r, e = range, enumerate\n ip = IP()\n id = Idea()\n\n \n n, m = ip.IL()\n a = ip.IL()\n c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n f = [-1] * n\n f[0] = 0\n\n for i in r(n):\n i += 1\n for x in a:\n if i - c[x] >= 0:\n f[i] = max(f[i], f[i - c[x]] * 10 + x)\n\n print(f[n])\n\n\nmain()\n', '# coding: utf-8\nimport sys\n\n\n# import math\n# import itertools\n# import numpy as np\n\n\n"""Template"""\n\n\nclass IP:\n \n\n def __init__(self):\n self.input = sys.stdin.readline\n\n def I(self):\n \n return int(self.input())\n\n def S(self):\n \n return self.input()\n\n def IL(self):\n \n return list(map(int, self.input().split()))\n\n def SL(self):\n \n return list(map(str, self.input().split()))\n\n def ILS(self, n):\n \n return [int(self.input()) for _ in range(n)]\n\n def SLS(self, n):\n \n return [self.input() for _ in range(n)]\n\n def SILS(self, n):\n \n return [self.IL() for _ in range(n)]\n\n def SSLS(self, n):\n \n return [self.SL() for _ in range(n)]\n\n\nclass Idea:\n def __init__(self):\n pass\n\n def HF(self, p):\n \n return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))\n\n def Bfs2(self, a):\n \n \n # https://blog.rossywhite.com/2018/08/06/bit-search/\n \n value = []\n for i in range(1 << len(a)):\n output = []\n\n for j in range(len(a)):\n if self.bit_o(i, j):\n \n # output.append(a[j])\n output.append(a[j])\n value.append([format(i, \'b\').zfill(16), sum(output)])\n\n value.sort(key=lambda x: x[1])\n bin = [value[k][0] for k in range(len(value))]\n val = [value[k][1] for k in range(len(value))]\n return bin, val\n\n def S(self, s, r=0, m=-1):\n \n r = bool(r)\n if m == -1:\n s.sort(reverse=r)\n else:\n s.sort(reverse=r, key=lambda x: x[m])\n\n def bit_n(self, a, b):\n \n return bool((a >> b & 1) > 0)\n\n def bit_o(self, a, b):\n \n return bool(((a >> b) & 1) == 1)\n\n def ceil(self, x, y):\n \n return -(-x // y)\n\n def ave(self, a):\n \n return sum(a) / len(a)\n\n def gcd(self, x, y):\n if y == 0:\n return x\n else:\n return self.gcd(y, x % y)\n\n\n\n\n\ndef main():\n \n r, e = range, enumerate\n ip = IP()\n id = Idea()\n\n \n n, m = ip.IL()\n a = ip.IL()\n c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] \n f = [0] + [-1] * 10010 # DP\n \n id.S(a, 1)\n \n \n for i in r(n):\n \n i += 1\n for x in a:\n if i - c[x] >= 0:\n f[i] = max(f[i], f[i - c[x]] * 10 + x)\n break\n\n print(f[n])\n print(f)\n\n\nmain()\n', '# coding: utf-8\nimport sys\n\n\n# import math\n# import itertools\n\n# import numpy as np\n\n\n"""Template"""\n\n\nclass IP:\n \n\n def __init__(self):\n self.input = sys.stdin.readline\n\n def I(self):\n \n return int(self.input())\n\n def S(self):\n \n return self.input()\n\n def IL(self):\n \n return list(map(int, self.input().split()))\n\n def SL(self):\n \n return list(map(str, self.input().split()))\n\n def ILS(self, n):\n \n return [int(self.input()) for _ in range(n)]\n\n def SLS(self, n):\n \n return [self.input() for _ in range(n)]\n\n def SILS(self, n):\n \n return [self.IL() for _ in range(n)]\n\n def SSLS(self, n):\n \n return [self.SL() for _ in range(n)]\n\n\nclass Idea:\n def __init__(self):\n pass\n\n def HF(self, p):\n \n return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))\n\n def Bfs2(self, a):\n \n \n # https://blog.rossywhite.com/2018/08/06/bit-search/\n \n value = []\n for i in range(1 << len(a)):\n output = []\n\n for j in range(len(a)):\n if self.bit_o(i, j):\n \n # output.append(a[j])\n output.append(a[j])\n value.append([format(i, \'b\').zfill(16), sum(output)])\n\n value.sort(key=lambda x: x[1])\n bin = [value[k][0] for k in range(len(value))]\n val = [value[k][1] for k in range(len(value))]\n return bin, val\n\n def S(self, s, r=0, m=-1):\n \n r = bool(r)\n if m == -1:\n s.sort(reverse=r)\n else:\n s.sort(reverse=r, key=lambda x: x[m])\n\n def bit_n(self, a, b):\n \n return bool((a >> b & 1) > 0)\n\n def bit_o(self, a, b):\n \n return bool(((a >> b) & 1) == 1)\n\n def ceil(self, x, y):\n \n return -(-x // y)\n\n def ave(self, a):\n \n return sum(a) / len(a)\n\n def gcd(self, x, y):\n if y == 0:\n return x\n else:\n return self.gcd(y, x % y)\n\n\n\n\n\ndef main():\n \n r, e = range, enumerate\n ip = IP()\n id = Idea()\n\n \n n, m = ip.IL()\n a = ip.IL()\n c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n f = [-1] * (n + 10)\n f[0] = 0\n\n for i in r(n):\n i += 1\n for x in a:\n if i - c[x] >= 0:\n f[i] = max(f[i], f[i - c[x]] * 10 + x)\n\n print(f[n])\n print(f)\n\n\nmain()\n', 'n, m = map(int, input().split())\na = list(map(int, input().split()))\nc = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] \nf = [0] + [0] * 10000 # DP\n\n\nfor i in range(n):\n \n i += 1\n for x in a:\n \n \n\n o = c[x] \n\n if i - o >= 0: \n \n f[i] = max(f[i], f[i - o] * 10 + x)\n\nprint(f[n])\n', 'n, m = map(int, input().split())\na = list(map(int, input().split()))\nc = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6] \nf = [0] + [-1] * 10000 # DP\n\n\nfor i in range(n):\n \n i += 1\n for x in a:\n \n \n\n o = c[x] \n\n if i - o >= 0: \n \n f[i] = max(f[i], f[i - o] * 10 + x)\n\nprint(f[n])\n'] | ['Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s548369968', 's611550373', 's840645342', 's864304429', 's526513304'] | [14500.0, 22336.0, 87968.0, 14388.0, 14388.0] | [133.0, 144.0, 1499.0, 151.0, 152.0] | [4894, 5077, 4914, 690, 691] |
p03128 | u207707177 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m = [int(i) for i in input().split()]\na = list(map(int,input().split()))\n\nmatch = [0,2,5,5,4,5,6,3,7,6]\n\ndig = [0] * (n+1)\n\ninf = 10**9\n\n\nfor i in range(1,n+1):\n lst = []\n for j in range(len(a)):\n num = a[j]\n mat = match[num]\n bef = i-mat\n if bef >= 0:\n lst.append(dig[bef])\n if lst:\n dig[i] = max(lst) + 1\n\n\nans = ""\ndef dp(i):\n if i == 0:\n return\n global ans\n maxi = 0\n for j in range(len(a)):\n num = a[j]\n mat = match[num]\n bef = i - mat\n if bef >= 0:\n if dig[bef] == dig[i]-1 and (dig[bef] > 0 or bef == 0):\n if num > maxi:\n maxi = num\n k = bef\n dp(k)\n\ndp(n)\nprint(ans)', 'n,m = [int(i) for i in input().split()]\na = list(map(int,input().split()))\n\nimport sys\nsys.setrecursionlimit(50000)\n\nmatch = [0,2,5,5,4,5,6,3,7,6]\n\ndig = [0] * (n+1)\n\ninf = 10**9\n\n\nfor i in range(1, n + 1):\n lst = []\n for j in range(len(a)):\n num = a[j]\n mat = match[num]\n bef = i - mat\n if bef >= 0:\n if bef == 0:\n lst.append(dig[bef])\n else:\n if dig[bef] > 0:\n lst.append(dig[bef])\n if lst:\n dig[i] = max(lst) + 1\n\n\nans = ""\n\n\ndef dp(i):\n k = -1\n if i == 0:\n return\n global ans\n maxi = 0\n for j in range(len(a)):\n num = a[j]\n mat = match[num]\n bef = i - mat\n if dig[i] == 1:\n if bef == 0:\n maxi = max(maxi, num)\n k = 0\n else:\n if bef >= 0:\n if dig[bef] == dig[i] - 1:\n if num > maxi:\n maxi = num\n k = bef\n ans += str(maxi)\n if k >= 0:\n dp(k)\n\n\ndp(n)\nprint(ans)'] | ['Runtime Error', 'Accepted'] | ['s622909391', 's344574227'] | [4392.0, 7768.0] | [157.0, 134.0] | [752, 1087] |
p03128 | u218494572 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import numpy as np\nimport math\n\nINF = 1000000\n\nN,M = map(int, input().split())\nmatch = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\nA = list(map(int, input().split()))\n\nmatch = {a:match[a] for a in A}\n\ndp = []\n\nfor i in range(N+1):\n if i == 0:\n dp.append(0)\n else:\n tmp = [dp[i-m] for m in match.values() if i-m >= 0]\n if tmp == []:\n dp.append(-float('inf'))\n else:\n dp.append(max(tmp)+1)\nprint(dp)\ns = ''\nnums = list(match.keys())\nnums.sort(reverse=True)\nprint(nums)\nwhile(True):\n for num in nums:\n if N - match[num] >= 0 and dp[N - match[num]] == dp[N] - 1:\n s = s + str(num)\n N-=match[num]\n break\n if N == 0:\n break\n\nprint(s)", "import numpy as np\nimport math\n\nINF = 1000000\n\nN,M = map(int, input().split())\nmatch = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\nA = list(map(int, input().split()))\n\nmatch = {a:match[a] for a in A}\n\ndp = []\n\nfor i in range(N+1):\n if i == 0:\n dp.append(0)\n else:\n tmp = [dp[i-m] for m in match.values() if i-m >= 0]\n if tmp == []:\n dp.append(-float('inf'))\n else:\n dp.append(max(tmp)+1)\n\ns = ''\nnums = list(match.keys())\nprint(nums)\nwhile(True):\n for num in nums:\n if N - match[num] >= 0 and dp[N - match[num]] == dp[N] - 1:\n s = s + str(num)\n N-=match[num]\n break\n if N == 0:\n break\n\nprint(s)\n", "import numpy as np\nimport math\n\nINF = 1000000\n\nN,M = map(int, input().split())\nmatch = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\nA = list(map(int, input().split()))\n\nmatch = {a:match[a] for a in A}\n\ndp = []\n\nfor i in range(N+1):\n if i == 0:\n dp.append(0)\n else:\n tmp = [dp[i-m] for m in match.values() if i-m >= 0]\n if tmp == []:\n dp.append(-float('inf'))\n else:\n dp.append(max(tmp)+1)\ns = ''\nnums = list(match.keys())\nnums.sort(reverse=True)\nwhile(True):\n for num in nums:\n if N - match[num] >= 0 and dp[N - match[num]] == dp[N] - 1:\n s = s + str(num)\n N-=match[num]\n break\n if N == 0:\n break\n\nprint(int(s))\n"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s523423940', 's928105906', 's458454263'] | [18960.0, 12528.0, 21268.0] | [304.0, 181.0, 318.0] | [738, 706, 722] |
p03128 | u219015402 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nlistA = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\ndp = [-1]*10010\ndp[0] = 0\nfor j in range(1, N+1):\n\tfor a in listA:\n\t\tif j-c[a] >= 0:\n\t\t\tdp[j] = max(dp[j], a*10 + dp[j-c[a]])\nprint(dp[N])', 'N, M = map(int, input().split())\nlistA = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\ndp = [-1]*N\ndp[0] = 0\nfor j in range(1, N+1):\n\tfor a in listA:\n\t\tif j-c[a] >= 0:\n\t\t\tdp[j] = max(dp[j], dp[j-c[a]]*10+a)\nprint(dp[N])', 'N, M = map(int, input().split())\nlistA = list(map(int, input().split()))\nc = [0,2,5,5,4,5,6,3,7,6]\ndp = [-1]*10010\ndp[0] = 0\nfor j in range(1, N+1):\n\tfor a in listA:\n\t\tif j-c[a] >= 0:\n\t\t\tdp[j] = max(dp[j], dp[j-c[a]]*10+a)\nprint(dp[N])'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s250691966', 's969961419', 's429370595'] | [3384.0, 14388.0, 14516.0] | [69.0, 158.0, 151.0] | [237, 231, 235] |
p03128 | u259418313 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = [int(a) for a in input().split()]\nL = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA.sort(reverse = True)\n\ndp = [0] + ([-1]*N)\nfor i in range(1, N+1):\n for a in A:\n if L[a] <= i:\n dp[i] = max(dp[i], dp[i-L[a]] * 10 + a)\n print(dp)\nprint(dp[-1])', 'N, M = map(int, input().split())\nA = [int(a) for a in input().split()]\nL = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA.sort(reverse = True)\n\ndp = [0] + ([-1]*N)\nfor i in range(1, N+1):\n for a in A:\n if L[a] <= i:\n dp[i] = max(dp[i], dp[i-L[a]] * 10 + a)\nprint(dp[-1])'] | ['Runtime Error', 'Accepted'] | ['s917762988', 's644989959'] | [135292.0, 14692.0] | [1546.0, 152.0] | [291, 277] |
p03128 | u261646994 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["N, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nnum_dict = {\n 1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6\n}\n\n\ncount_list = [num_dict[a] for a in A]\n\n\nmin_matches = min(count_list)\n\n\nmin_num_list = []\n[min_num_list.append(a) for a in A if num_dict[a] == min_matches]\nmin_num = max(min_num_list)\n\n\n\nA.sort(reverse=True)\nres = {a: num_dict[a]-min_matches for a in A}\n\n\ndef dfs(nums, target, num_count):\n if len(nums) > num_count:\n return None\n if target == 0:\n return nums\n elif target < 0:\n return None\n else:\n for a in A:\n ret = dfs(nums+[a], target-res[a], num_count)\n if ret is not None:\n return ret\n return None\n\n\nfor num_count in range(N//min_matches, 0, -1):\n \n mod = N - min_matches*num_count\n\n print(num_count, mod, num_count)\n\n \n share = dfs([], mod, num_count)\n if share is not None:\n out_list = sorted([min_num]*(num_count-len(share))+share, reverse=True)\n out_list = [str(item) for item in out_list]\n print(''.join(out_list))\n break\n", "from collections import defaultdict\nimport sys\nsys.setrecursionlimit(10000)\n\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nnum_dict = {\n 1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6\n}\nA.sort(reverse=True)\n\n\ndp = defaultdict(lambda: -1e18)\ndp[0] = 0\n\nfor i in range(2, N+1):\n dp[i] = max([dp[i-num_dict[a]]+1 for a in A])\n\nnum_count = dp[N]\n\nout_list = []\nres_N = N\nfor _ in range(num_count):\n for a in A:\n if dp[res_N]-1 == dp[res_N-num_dict[a]]:\n out_list.append(str(a))\n res_N = res_N - num_dict[a]\n break\n\nprint(''.join(out_list))\n"] | ['Runtime Error', 'Accepted'] | ['s585037341', 's784335230'] | [7872.0, 4720.0] | [2104.0, 56.0] | [1331, 667] |
p03128 | u263830634 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import sys\nsys.setrecursionlimit(4 * (10 ** 9))\nlst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort(reverse = True)\n# print (A)\n\ndef num(k):\n return lst[k-1][1]\n\n\n # print (num(i), end = ', ')\n# print ()\n\nINF = 10 ** 5\ndp_lst = [-INF] * (N + 1)\ndp_lst[0] = 0\ndef dp(i):\n if dp_lst[i] != -INF:\n return dp_lst[i]\n tmp = -INF\n for j in A:\n if i >= num(j):\n tmp = max(tmp, dp(i - num(j)) + 1)\n dp_lst[i] = tmp\n return dp_lst[i]\n\na = dp(N)\n# print (a)\n# print (dp_lst) \n\n\n# print (len(str(71111111111111111111111111111111111111111111111111)))\n\ndef check(A):\n if dp_lst[N-num(A)] == dp_lst[N] - 1:\n return True\n else:\n return False\n\n# print (a)\nwhile a > 0:\n for i in A:\n if check(i):\n print (i, end = '')\n N -= num(i)\n a -= 1\n break\n else:\n pass\n # print ('B')\nprint ()", "import sys\nsys.setrecursionlimit(10 ** 10)\nlst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort(reverse = True)\n# print (A)\n\ndef num(k):\n return lst[k-1][1]\n\n\n # print (num(i), end = ', ')\n# print ()\n\nINF = 10 ** 9\ndp_lst = [-INF] * (N + 1)\ndp_lst[0] = 0\ndef dp(i):\n if dp_lst[i] != -INF:\n return dp_lst[i]\n tmp = -INF\n for j in A:\n if i >= num(j):\n tmp = max(tmp, dp(i - num(j)) + 1)\n dp_lst[i] = tmp\n return dp_lst[i]\n\na = dp(N)\n# print (a)\n# print (dp_lst) \n\n\n# print (len(str(71111111111111111111111111111111111111111111111111)))\n\ndef check(A):\n if dp_lst[N-num(A)] == dp_lst[N] - 1:\n return True\n else:\n return False\n\n# print (a)\nwhile a > 0:\n for i in A:\n if check(i):\n print (i, end = '')\n N -= num(i)\n a -= 1\n break\n else:\n pass\n # print ('B')\nprint ()", "import sys\nsys.setrecursionlimit(10 ** 5)\nlst = [[1,2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort(reverse = True)\n# print (A)\n\ndef num(k):\n return lst[k-1][1]\n\n\n # print (num(i), end = ', ')\n# print ()\n\nINF = 10 ** 5\ndp_lst = [-INF] * (N + 1)\ndp_lst[0] = 0\ndef dp(i):\n if dp_lst[i] != -INF:\n return dp_lst[i]\n tmp = -INF\n for j in A:\n if i >= num(j):\n tmp = max(tmp, dp(i - num(j)) + 1)\n dp_lst[i] = tmp\n return dp_lst[i]\n\na = dp(N)\n# print (a)\n# print (dp_lst) \n\n\n# print (len(str(71111111111111111111111111111111111111111111111111)))\n\ndef check(A):\n if N - num(A) < 0:\n return False\n if dp_lst[N-num(A)] == dp_lst[N] - 1:\n return True\n else:\n return False\n\n# print (a)\nwhile a > 0:\n for i in A:\n if check(i):\n print (i, end = '')\n N -= num(i)\n a -= 1\n break\n else:\n pass\n # print ('B')\nprint ()"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s338005330', 's419349836', 's206959770'] | [3064.0, 3064.0, 5364.0] | [18.0, 18.0, 114.0] | [1074, 1069, 1112] |
p03128 | u272557899 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n, m = map(int, input().split())\na = [int(m) for m in input().split()]\na.sort(reverse=True)\ndp = []\nfor i in range(10 * n):\n dp.append(0)\n\nb = [0,2,5,5,4,5,6,3,7,6]\nfor i in range(1, n + 1):\n for j in range(len(a)):\n if i - b[a[j]] >= 0:\n dp[i] = max(dp[i], dp[i - b[a[j]]] + a[j])\n else:\n pass\n if i != n:\n dp[i] *= 10\n\nprint(dp[n])', 'n, m = map(int, input().split())\na = [int(m) for m in input().split()]\na.sort(reverse=True)\ndp = []\nfor i in range(10 * n):\n dp.append(0)\n\nb = [0,2,5,5,4,5,6,3,7,6]\nfor i in range(1, n + 1):\n for j in range(len(a)):\n if i - b[a[j]] >= 0:\n if (dp[i - b[a[j]]] == 0 and i - b[a[j]] == 0) or dp[i - b[a[j]]] != 0:\n dp[i] = max(dp[i], dp[i - b[a[j]]] + a[j])\n else:\n pass\n if i != n:\n dp[i] *= 10\n\nprint(dp[n])'] | ['Wrong Answer', 'Accepted'] | ['s813689131', 's180283128'] | [15276.0, 15272.0] | [135.0, 176.0] | [385, 473] |
p03128 | u280512618 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import sys\n\nmp = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nif __name__ == '__main__':\n n, m = map(int, input().split())\n a = sorted(input().split(), reverse=True)\n\n dp = [-10007] * (n + 1)\n dp[0] = 0\n for i in a:\n step = mp[int(i)]\n for j in range(step, n + 1):\n dp[j] = max(dp[j - step] + 1, dp[j])\n\n print(dp)\n i = n\n while i > 0:\n for x in a:\n step = mp[int(x)]\n if i >= step and dp[i - step] == dp[i] - 1:\n sys.stdout.write(x)\n i -= step\n break\n print()\n", "import sys\n\nmp = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nif __name__ == '__main__':\n n, m = map(int, input().split())\n a = sorted(input().split(), reverse=True)\n\n dp = [-10007] * (n + 1)\n dp[0] = 0\n for i in a:\n step = mp[int(i)]\n for j in range(step, n + 1):\n dp[j] = max(dp[j - step] + 1, dp[j])\n\n i = n\n while i > 0:\n for x in a:\n step = mp[int(x)]\n if i >= step and dp[i - step] == dp[i] - 1:\n sys.stdout.write(x)\n i -= step\n break\n print()\n"] | ['Wrong Answer', 'Accepted'] | ['s055667752', 's735306485'] | [3956.0, 3828.0] | [81.0, 87.0] | [574, 560] |
p03128 | u284854859 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['def f(x):\n if x == 1:\n return 2\n if x == 2:\n return 5\n if x == 3:\n return 5\n if x == 4:\n return 4\n if x == 5:\n return 5\n if x == 6:\n return 6\n if x == 7:\n return 3\n if x == 8:\n return 7\n if x == 9:\n return 6\nn,m = map(int,input().split())\na = list(map(int,input().split()))\nif 2 in a and 3 in a:\n a.remove(2)\n m -=1\nif 2 in a and 5 in a:\n a.remove(2)\n m -=1\nif 3 in a and 5 in a:\n a.remove(3)\n m -=1\nif 6 in a and 9 in a:\n a.remove(6)\n m -=1\nfor w in range(1,10):\n if n < f(w):\n a.remove(w)\n m -=1\na.sort()\nm = len(a)\n\ndp = [[0]*(m+1) for i in range(n+2)]\n\n\ndef g(k):\n cand = [0]*(m+1)\n for i in range(m):\n if k - f(a[i])>=0:\n if cand[0] <= dp[k-f(a[i])][0]+1 and dp[k-f(a[i])][0] != 0:\n for r in range(m+1):\n cand[r] = dp[k-f(a[i])][r]\n cand[0] += 1\n cand[i+1] += 1\n if sum(cand) != 0:\n dp[k] = cand\nfor i in range(m):\n if f(a[i]) <= n:\n dp[f(a[i])][0] = 1\n dp[f(a[i])][i+1] = 1\nprint(1) ', "# cook your dish here\ndef f(x):\n if x == 1:\n return 2\n if x == 2:\n return 5\n if x == 3:\n return 5\n if x == 4:\n return 4\n if x == 5:\n return 5\n if x == 6:\n return 6\n if x == 7:\n return 3\n if x == 8:\n return 7\n if x == 9:\n return 6\nn,m = map(int,input().split())\na = list(map(int,input().split()))\nif 2 in a and 3 in a:\n a.remove(2)\n m -=1\nif 2 in a and 5 in a:\n a.remove(2)\n m -=1\nif 3 in a and 5 in a:\n a.remove(3)\n m -=1\nif 6 in a and 9 in a:\n a.remove(6)\n m -=1\nfor w in range(1,10):\n if n < f(w) and w in a:\n a.remove(w)\n m -=1\na.sort()\nm = len(a)\n\ndp = [[0]*(m+1) for i in range(n+2)]\n\n\ndef g(k):\n cand = [0]*(m+1)\n for i in range(m):\n if k - f(a[i])>=0:\n if cand[0] <= dp[k-f(a[i])][0]+1 and dp[k-f(a[i])][0] != 0:\n for r in range(m+1):\n cand[r] = dp[k-f(a[i])][r]\n cand[0] += 1\n cand[i+1] += 1\n if sum(cand) != 0:\n dp[k] = cand\nfor i in range(m):\n if f(a[i]) <= n:\n dp[f(a[i])][0] = 1\n dp[f(a[i])][i+1] = 1\n\nfor j in range(1,n+1):\n g(j)\n\nass = ''\n\nfor i in range(m):\n for k in range(dp[n][m-i]):\n ass += str(a[m-i-1])\nprint(ass) "] | ['Runtime Error', 'Accepted'] | ['s294040482', 's767148732'] | [4340.0, 4788.0] | [23.0, 126.0] | [1135, 1301] |
p03128 | u307842323 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\nsys.setrecursionlimit(1000000)\n\nN,M = map(int,input().split())\nma = list(map(int,input().split()))\nn = len(a)\nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nmemo = [-1] * 100000\n\ndef dp(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n\n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\tret = max(dp(num - ma_map[p]) * 10 + p, ret)\n\n\tmemo[num] = ret\n\treturn ret\n\nma.sort()\nprint(dp(N))\n', 'import sys\nsys.setrecursionlimit(1000000)\n \nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n \ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n \n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n \n\tmemo[num] = ret\n\treturn ret\n \nma.sort()\nprint(dfs(N))'] | ['Runtime Error', 'Accepted'] | ['s289180450', 's455292054'] | [3064.0, 17116.0] | [18.0, 153.0] | [414, 427] |
p03128 | u316386814 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["n, m = list(map(int, input().split()))\nli = list(map(int, input().split()))\ndi = {}\nfor i, d in enumerate([2,5,5,4,5,6,3,7,6], 1):\n di[i] = d\nli.sort(reverse=True)\nhons = set(di[a] for a in li)\ndd = {}\nfor a in li:\n hon = di[a]\n if hon not in dd:\n dd[hon] = a\n\nh2d = [0]\npre = [None]\nfor i in range(1, n + 1):\n res = -float('inf')\n p = None\n for hon in hons:\n if i < hon:\n continue\n dig = h2d[i - hon] + 1\n if dig > res:\n res = dig\n p = i - hon\n h2d.append(res)\n pre.append(p)\n print(i, res, p)\n\nans = []\nwhile n > 0:\n ans.append(dd[n - pre[n]])\n n = pre[n]\nans.sort(reverse=True)\nprint(*ans, sep='')\n", "n, m = list(map(int, input().split()))\nli = list(map(int, input().split()))\ndi = {}\nfor i, d in enumerate([2,5,5,4,5,6,3,7,6], 1):\n di[i] = d\nli.sort(reverse=True)\ndd = {}\nfor a in li:\n hon = di[a]\n if hon not in dd:\n dd[hon] = a\n\nh2d = [-float('inf')] * (n + 1)\nh2d[0] = 0\npre = [None] * (n + 1)\nfor j in range(1, n + 1):\n for a in li:\n ho = di[a]\n if j < ho:\n continue\n dig = h2d[j - ho] + 1\n if dig > h2d[j]:\n h2d[j] = dig\n pre[j] = j - ho\n\nans = []\nwhile n > 0:\n ans.append(dd[n - pre[n]])\n n = pre[n]\nans.sort(reverse=True)\nprint(*ans, sep='')\n"] | ['Wrong Answer', 'Accepted'] | ['s355263010', 's774700556'] | [5144.0, 4724.0] | [63.0, 60.0] | [695, 635] |
p03128 | u333190709 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import numpy as np\n\nN, M = [int(n) for n in input().split()]\nA = sorted([int(n) for n in input().split()])\nB = [2, 5, 5, 4, 5, 6, 3, 7, 6]\nC = [B[a - 1] for a in A]\n\nketa = N // min(C)\n\na = ""\n\nfor i in range(keta):\n res = N - min(C) * (keta - i)\n if res == 0:\n b = A[C.index(min(C))]\n a += "{}".format(b)\n else:\n if min(C) + res > max(C):\n b = A[C.index(max(C))]\n else:\n c = max([c for c in C if c <= min(C) + res])\n b = A[C.index(c)]\n a += "{}".format(b)\n\nprint(a)\n', '#!/usr/bin/env python3\nimport sys, math, fractions, itertools\n\nl = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndef solve(N: int, M: int, A: "List[int]"):\n dp = [-1] * (N+10) \n dp[0] = 0 \n for i in range(N-1): \n for s in A: \n if dp[i] == -1 and i!=0: \n continue\n if dp[i + l[s]] < dp[i]*10+s:\n dp[i + l[s]] = dp[i]*10+s\n print(dp[N])\n return\n\n\n# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)\ndef main():\n def iterate_tokens():\n for line in sys.stdin:\n for word in line.split():\n yield word\n tokens = iterate_tokens()\n N = int(next(tokens)) # type: int\n M = int(next(tokens)) # type: int\n A = [ int(next(tokens)) for _ in range(M) ] # type: "List[int]"\n solve(N, M, A)\n\nif __name__ == \'__main__\':\n main()\n'] | ['Wrong Answer', 'Accepted'] | ['s794887355', 's345250962'] | [12416.0, 16692.0] | [160.0, 226.0] | [544, 1078] |
p03128 | u334712262 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['# -*- coding: utf-8 -*-\nimport bisect\nimport heapq\nimport math\nimport random\nimport sys\nimport copy\nfrom collections import Counter, defaultdict, deque\nfrom decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal\nfrom functools import lru_cache, reduce\nfrom itertools import combinations, combinations_with_replacement, product, permutations\nfrom operator import add, mul, sub\n\nsys.setrecursionlimit(10000)\n\n\ndef read_int():\n return int(input())\n\n\ndef read_int_n():\n return list(map(int, input().split()))\n\n\ndef read_float():\n return float(input())\n\n\ndef read_float_n():\n return list(map(float, input().split()))\n\n\ndef read_str():\n return input().strip()\n\n\ndef read_str_n():\n return list(map(str, input().split()))\n\n\ndef error_print(*args):\n print(*args, file=sys.stderr)\n\n\ndef mt(f):\n import time\n\n def wrap(*args, **kwargs):\n s = time.time()\n ret = f(*args, **kwargs)\n e = time.time()\n\n error_print(e - s, \'sec\')\n return ret\n\n return wrap\n\n\n@mt\ndef slv(N, M, A):\n c = [\n -1,\n 2, # 1 \n 5, # 2\n 5, # 3\n 4, # 4\n 5, # 5\n 6, # 6\n 3, # 7\n 7, # 8\n 6, # 9\n ]\n \n if 2 in A and 5 in A:\n A.remove(2)\n if 3 in A and 5 in A:\n A.remove(3)\n if 2 in A and 3 in A:\n A.remove(2)\n if 6 in A and 9 in A:\n A.remove(6)\n\n\n\n dp = [None] * (N+1) \n dp[N] = (0, Counter())\n for i in range(N, 0, -1):\n print(i)\n if dp[i] is None:\n continue\n \n for a in A:\n if i - c[a] < 0:\n continue\n \n if dp[i-c[a]] is None:\n c_ = copy.deepcopy(dp[i][1])\n c_[a] += 1\n dp[i-c[a]] = (dp[i][0]+1, c_)\n \n elif dp[i][0]+1 > dp[i-c[a]][0]:\n c_ = copy.deepcopy(dp[i][1])\n c_[a] += 1\n dp[i-c[a]] = (dp[i][0]+1, c_)\n\n ans = ""\n for r in sorted(dp[0][1], reverse=True):\n ans += str(r) * dp[0][1][r]\n return ans\n\n\ndef main():\n # N = read_int()\n N, M = read_int_n()\n A = read_int_n()\n print(slv(N, M, A))\n\n\nif __name__ == \'__main__\':\n main()\n', "# -*- coding: utf-8 -*-\nimport bisect\nimport heapq\nimport math\nimport random\nimport sys\nimport copy\nfrom collections import Counter, defaultdict, deque\nfrom decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal\nfrom functools import lru_cache, reduce\nfrom itertools import combinations, combinations_with_replacement, product, permutations\nfrom operator import add, mul, sub\n\nsys.setrecursionlimit(10000)\n\n\ndef read_int():\n return int(input())\n\n\ndef read_int_n():\n return list(map(int, input().split()))\n\n\ndef read_float():\n return float(input())\n\n\ndef read_float_n():\n return list(map(float, input().split()))\n\n\ndef read_str():\n return input().strip()\n\n\ndef read_str_n():\n return list(map(str, input().split()))\n\n\ndef error_print(*args):\n print(*args, file=sys.stderr)\n\n\ndef mt(f):\n import time\n\n def wrap(*args, **kwargs):\n s = time.time()\n ret = f(*args, **kwargs)\n e = time.time()\n\n error_print(e - s, 'sec')\n return ret\n\n return wrap\n\n\n@mt\ndef slv(N, M, A):\n c = [\n -1,\n 2, # 1 \n 5, # 2\n 5, # 3\n 4, # 4\n 5, # 5\n 6, # 6\n 3, # 7\n 7, # 8\n 6, # 9\n ]\n \n if 2 in A and 5 in A:\n A.remove(2)\n if 3 in A and 5 in A:\n A.remove(3)\n if 2 in A and 3 in A:\n A.remove(2)\n if 6 in A and 9 in A:\n A.remove(6)\n\n\n\n dp = [None] * (N+1) \n dp[N] = 0\n for i in range(N, 0, -1):\n if dp[i] is None:\n continue\n \n for a in A:\n if i - c[a] < 0:\n continue\n \n if dp[i-c[a]] is None or dp[i] * 10 + a > dp[i-c[a]]:\n dp[i-c[a]] = dp[i] * 10 + a\n\n return dp[0]\n\n\ndef main():\n # N = read_int()\n N, M = read_int_n()\n A = read_int_n()\n print(slv(N, M, A))\n\n\nif __name__ == '__main__':\n main()\n"] | ['Wrong Answer', 'Accepted'] | ['s459746899', 's341884826'] | [9816.0, 17084.0] | [867.0, 157.0] | [2215, 1872] |
p03128 | u338225045 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map( int, input().split() )\nA = list( map( int, input().split() ) )\n\n\n\ndp = [-float(\'inf\')] * (N+1) \ncost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ] \n\ndp[0] = 0\nfor num_match in range( 2, N+1 ):\n for Aj in A:\n if num_match >= cost[Aj]:\n dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )\n\n\nprint( dp )\n\nans = ""\ndigit = dp[N]\n\nA.sort( reverse=True )\nwhile N > 0:\n for Ai in A:\n if dp[N-cost[Ai]] == digit-1 :\n ans += str(Ai)\n N -= cost[Ai]\n digit -= 1\n break\n\nprint( ans )', 'N, M = map( int, input().split() )\nA = list( map( int, input().split() ) )\n\n\n\ndp = [0]*(N+1) \ncost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ] \n\nfor num_match in range( 2, N+1 ):\n for Aj in A:\n if num_match >= cost[Aj]:\n dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )\n\n\n\nans = ""\ndigit = dp[N]\n\nA.sort( reverse=True )\nwhile N > 0:\n for Ai in A:\n if N-cost[Ai] >=0 and dp[N-cost[Ai]] == digit-1:\n ans += str(Ai)\n N -= cost[Ai]\n digit -= 1\n break\n\nprint( ans )', 'N, M = map( int, input().split() )\nA = list( map( int, input().split() ) )\n\n\n\ndp = [0] + [-float(\'inf\')] * (N+1) \ncost = [ 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 ] \n\nfor num_match in range( 2, N+1 ):\n for Aj in A:\n if num_match >= cost[Aj]:\n dp[num_match] = max( dp[num_match], dp[num_match-cost[Aj]]+1 )\n\n\nans = ""\ndigit = dp[N]\n\nA.sort( reverse=True )\nwhile N > 0:\n for Ai in A:\n if N-cost[Ai] >=0 and dp[N-cost[Ai]] == digit-1:\n ans += str(Ai)\n N -= cost[Ai]\n digit -= 1\n break\n\nprint( ans )'] | ['Runtime Error', 'Time Limit Exceeded', 'Accepted'] | ['s446336652', 's725406557', 's618285917'] | [3568.0, 3380.0, 3440.0] | [84.0, 2104.0, 90.0] | [783, 813, 778] |
p03128 | u346851130 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n costs = list(map(int, input().split()))\n costs = [(c, COSTS[c]) for c in costs]\n costs.sort(key=lambda x:x[1])\n\n num, cost = costs[0]\n nums = [num] * (remain // cost)\n remain -= cost * len(nums)\n\n if remain != 0:\n new_costs = []\n exists = set([0])\n\n for n, c in costs:\n nc = c - cost\n\n if nc <= remain and nc not in exists:\n new_costs.append((n, nc))\n\n #max_repeat = min(remain // min(v[1] for v in new_costs), len(nums))\n #rep_nums_list = []\n\n #for repeat in range(1, max_repeat + 1):\n # for idxs in itertools.product(range(len(new_costs)), repeat=repeat):\n \n\n \n # continue\n\n \n\n #max_nums = [0] * len(nums)\n\n #for rep_nums in rep_nums_list:\n \n \n # new_nums = nums[:]\n\n # if len(uns) > 0:\n \n\n # if len(lns) > 0:\n # new_nums = new_nums[:-len(lns)] + lns\n\n # if new_nums > max_nums:\n # max_nums = new_nums\n\n #nums = max_nums\n\n print(''.join(str(v) for v in nums), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n cs.sort(key=lambda x:-x[0])\n cs = [(p, c - b) for p, c in cs if c != b]\n ds = None\n\n for i in range(1, len(cs) + 1):\n for ps in itertools.product(range(len(cs)), repeat=i):\n if sum(cs[p][1] for p in ps) == n:\n ds = [cs[p][0] for p in ps]\n break\n\n if ds is not None:\n break\n\n uds = [d for d in ds if d >= s]\n lds = [d for d in ds if d < s][::-1]\n\n a = uds + a[len(uds):]\n a = a[-len(lds):] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef gen(base_digit, base_cost, base_length, digits, remain):\n number = [base_digit] * base_length\n remain -= base_cost * base_length\n\n if remain == 0:\n print(''.join(str(d) for d in number), flush=True)\n return True\n\n digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]\n \n if len(digits) == 0:\n return False\n\n max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))\n numbers = []\n\n for repeat in range(1, max_repeat + 1):\n for idxs in itertools.product(range(len(digits)), repeat=repeat):\n if sum(digits[i][1] for i in idxs) != remain:\n continue\n\n \n # uppers = [d for d in replaces if d > base_digit]\n # lowers = [d for d in replaces if d < base_digit]\n\n num = number[:]\n\n # if len(uppers) > 0:\n \n\n # if len(lowers) > 0:\n \n\n numbers.append(num)\n\n if len(numbers) == 0:\n return False\n\n number = max(numbers)\n\n print(''.join(str(d) for d in number), flush=True)\n\n return True\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n digits = {}\n\n for d in map(int, input().split()):\n if COSTS[d] not in digits or digits[COSTS[d]] < d:\n digits[COSTS[d]] = d\n\n digits = [(d, c) for c, d in digits.items()]\n base_digit, base_cost = min(digits, key=lambda x: x[1])\n\n for length in range(remain // base_cost, -1, -1):\n if gen(base_digit, base_cost, length, digits, remain):\n break\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n #cs.sort(key=lambda x:-x[0])\n #cs = [(p, c - b) for p, c in cs if c != b]\n #ds = None\n\n \n # for ps in itertools.product(range(len(cs)), repeat=i):\n # if sum(cs[p][1] for p in ps) == n:\n # ds = [cs[p][0] for p in ps]\n # break\n\n # if ds is not None:\n # break\n\n #uds = [d for d in ds if d >= s]\n #lds = [d for d in ds if d < s][::-1]\n\n #if len(uds) > 0:\n \n #if len(lds) > 0:\n # a = a[:-len(lds)] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n costs = list(map(int, input().split()))\n costs = [(c, COSTS[c]) for c in costs]\n costs.sort(key=lambda x:x[1])\n\n num, cost = costs[0]\n costs.sort(key=lambda x:-x[0])\n\n nums = [num] * (remain // cost)\n remain -= cost * len(nums)\n\n if remain != 0:\n new_costs = []\n exists = set([0])\n\n for n, c in costs:\n nc = c - cost\n\n if nc <= remain and nc not in exists:\n new_costs.append((n, nc))\n\n max_repeat = min(remain // min(v[1] for v in new_costs), len(nums))\n rep_nums_list = []\n\n for repeat in range(1, max_repeat + 1):\n for idxs in itertools.product(range(len(new_costs)), repeat=repeat):\n nc = sum(new_costs[i][1] for i in idxs)\n\n if nc != remain:\n continue\n\n rep_nums_list.append([new_costs[i][0] for i in idxs])\n\n #max_nums = [0] * len(nums)\n\n #for rep_nums in rep_nums_list:\n \n \n # new_nums = nums[:]\n\n # if len(uns) > 0:\n \n\n # if len(lns) > 0:\n # new_nums = new_nums[:-len(lns)] + lns\n\n # if new_nums > max_nums:\n # max_nums = new_nums\n\n #nums = max_nums\n\n print(''.join(str(v) for v in nums), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef gen(base_digit, base_cost, base_length, digits, remain):\n\n number = [base_digit] * base_length\n remain -= base_cost * base_length\n\n digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]\n max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))\n numbers = []\n\n for repeat in range(1, max_repeat + 1):\n for idxs in itertools.product(range(len(digits)), repeat=repeat):\n if sum(digits[i][1] for i in idxs) != remain:\n continue\n\n \n # uppers = [d for d in replaces if d > base_digit]\n # lowers = [d for d in replaces if d < base_digit]\n\n num = number[:]\n\n # if len(uppers) > 0:\n \n\n # if len(lowers) > 0:\n \n\n numbers.append(num)\n\n if len(numbers) == 0:\n return False\n\n number = max(numbers)\n\n print(''.join(str(d) for d in number))\n\n return True\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n digits = {}\n\n for d in map(int, input().split()):\n if COSTS[d] not in digits or digits[COSTS[d]] < d:\n digits[COSTS[d]] = d\n\n digits = [(d, c) for c, d in digits.items()]\n base_digit, base_cost = min(digits, key=lambda x: x[1])\n\n for length in range(remain // base_cost, -1, -1):\n if gen(base_digit, base_cost, length, digits, remain):\n break\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n cs.sort(key=lambda x:-x[0])\n cs = [(p, c - b) for p, c in cs if c != b]\n ds = None\n\n for i in range(1, len(cs) + 1):\n for ps in itertools.product(range(len(cs)), repeat=i):\n if sum(cs[p][1] for p in ps) == n:\n ds = [cs[p][0] for p in ps]\n break\n\n if ds is not None:\n break\n\n \n # lds = [d for d in ds if d < s][::-1]\n\n # if len(uds) > 0:\n \n # if len(lds) > 0:\n # a = a[:-len(lds)] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n cs.sort(key=lambda x:-x[0])\n cs = [(p, c - b) for p, c in cs if c != b]\n\n for i in range(1, len(cs) + 1):\n for ps in itertools.product(range(len(cs)), repeat=i):\n if sum(cs[p][1] for p in ps) == n:\n ds = [cs[p][0] for p in ps]\n break\n\n uds = [d for d in ds if d >= s]\n lds = [d for d in ds if d < s][::-1]\n\n a = uds + a[len(uds):]\n a = a[-len(lds):] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef gen(base_digit, base_cost, base_length, digits, remain):\n number = [base_digit] * base_length\n remain -= base_cost * base_length\n\n if remain == 0:\n print(''.join(str(d) for d in number), flush=True)\n return True\n\n print(''.join(str(d) for d in number), flush=True)\n return True\n\n digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]\n max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))\n numbers = []\n\n for repeat in range(1, max_repeat + 1):\n for idxs in itertools.product(range(len(digits)), repeat=repeat):\n if sum(digits[i][1] for i in idxs) != remain:\n continue\n\n \n # uppers = [d for d in replaces if d > base_digit]\n # lowers = [d for d in replaces if d < base_digit]\n\n num = number[:]\n\n # if len(uppers) > 0:\n \n\n # if len(lowers) > 0:\n \n\n numbers.append(num)\n\n if len(numbers) == 0:\n return False\n\n number = max(numbers)\n\n print(''.join(str(d) for d in number), flush=True)\n\n return True\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n digits = {}\n\n for d in map(int, input().split()):\n if COSTS[d] not in digits or digits[COSTS[d]] < d:\n digits[COSTS[d]] = d\n\n digits = [(d, c) for c, d in digits.items()]\n base_digit, base_cost = min(digits, key=lambda x: x[1])\n\n for length in range(remain // base_cost, -1, -1):\n if gen(base_digit, base_cost, length, digits, remain):\n break\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n cs.sort(key=lambda x:-x[0])\n cs = [(p, c - b) for p, c in cs if c != b]\n ds = None\n\n for i in range(1, len(cs) + 1):\n for ps in itertools.product(range(len(cs)), repeat=i):\n print(ps)\n if sum(cs[p][1] for p in ps) == n:\n ds = [cs[p][0] for p in ps]\n break\n\n if ds is not None:\n break\n\n uds = [d for d in ds if d >= s]\n lds = [d for d in ds if d < s][::-1]\n\n a = uds + a[len(uds):]\n a = a[-len(lds):] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n cs.sort(key=lambda x:-x[0])\n cs = [(p, c - b) for p, c in cs if c != b]\n ds = None\n\n \n # for ps in itertools.product(range(len(cs)), repeat=i):\n # if sum(cs[p][1] for p in ps) == n:\n # ds = [cs[p][0] for p in ps]\n # break\n\n # if ds is not None:\n # break\n\n #uds = [d for d in ds if d >= s]\n #lds = [d for d in ds if d < s][::-1]\n\n #if len(uds) > 0:\n \n #if len(lds) > 0:\n # a = a[:-len(lds)] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef gen(base_digit, base_cost, base_length, digits, remain):\n number = [base_digit] * base_length\n remain -= base_cost * base_length\n\n if remain == 0:\n print(''.join(str(d) for d in number), flush=True)\n return True\n\n digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]\n max_repeat = min(remain // min(digits, key=lambda x: x[1])[1], len(number))\n numbers = []\n\n for repeat in range(1, max_repeat + 1):\n for idxs in itertools.product(range(len(digits)), repeat=repeat):\n if sum(digits[i][1] for i in idxs) != remain:\n continue\n\n \n # uppers = [d for d in replaces if d > base_digit]\n # lowers = [d for d in replaces if d < base_digit]\n\n num = number[:]\n\n # if len(uppers) > 0:\n \n\n # if len(lowers) > 0:\n \n\n numbers.append(num)\n\n if len(numbers) == 0:\n return False\n\n number = max(numbers)\n\n print(''.join(str(d) for d in number), flush=True)\n\n return True\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n digits = {}\n\n for d in map(int, input().split()):\n if COSTS[d] not in digits or digits[COSTS[d]] < d:\n digits[COSTS[d]] = d\n\n digits = [(d, c) for c, d in digits.items()]\n base_digit, base_cost = min(digits, key=lambda x: x[1])\n\n for length in range(remain // base_cost, -1, -1):\n if gen(base_digit, base_cost, length, digits, remain):\n break\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\n\ndef main():\n r = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n n, _ = list(map(int, input().split()))\n ps = list(map(int, input().split()))\n\n cs = [(p, r[p]) for p in ps]\n cs.sort(key=lambda x: x[1])\n a = []\n s, b = cs[0]\n\n while n - b > 0:\n a.append(s)\n n -= b\n\n cs.sort(key=lambda x:-x[0])\n cs = [(p, c - b) for p, c in cs if c != b]\n ds = None\n\n for i in range(1, len(cs) + 1):\n for ps in itertools.product(range(len(cs)), repeat=i):\n if sum(cs[p][1] for p in ps) == n:\n ds = [cs[p][0] for p in ps]\n break\n\n if ds is not None:\n break\n\n uds = [d for d in ds if d >= s]\n lds = [d for d in ds if d < s][::-1]\n\n # if len(uds) > 0:\n \n # if len(lds) > 0:\n # a = a[:-len(lds)] + lds\n\n print(''.join(str(v) for v in a), flush=True)\n\n\nif __name__ == '__main__':\n main()\n\n", "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nimport itertools\n\nCOSTS = (99, 2, 5, 5, 4, 5, 6, 3, 7, 6)\n\n\ndef gen(base_digit, base_cost, base_length, digits, remain):\n number = [base_digit] * base_length\n remain -= base_cost * base_length\n\n if remain == 0:\n print(''.join(str(d) for d in number), flush=True)\n return True\n\n digits = [(d, c - base_cost) for d, c in digits if d != base_digit and c - base_cost <= remain]\n\n if len(digits) == 0:\n return False\n\n max_size = min(remain // min(digits, key=lambda x: x[1])[1], len(number))\n numbers = []\n\n for size in range(1, max_size + 1):\n for idxs in itertools.combinations_with_replacement(range(len(digits)), size):\n if sum(digits[i][1] for i in idxs) != remain:\n continue\n\n replaces = [digits[i][0] for i in idxs]\n replaces.sort(reverse=True)\n uppers = [d for d in replaces if d > base_digit]\n lowers = [d for d in replaces if d < base_digit]\n\n num = number[:]\n\n if len(uppers) > 0:\n num = uppers + num[len(uppers):]\n\n if len(lowers) > 0:\n num = num[:-len(lowers)] + lowers\n\n numbers.append(num)\n\n if len(numbers) == 0:\n return False\n\n number = max(numbers)\n\n print(''.join(str(d) for d in number), flush=True)\n\n return True\n\n\ndef main():\n remain, _ = list(map(int, input().split()))\n\n digits = {}\n\n for d in map(int, input().split()):\n if COSTS[d] not in digits or digits[COSTS[d]] < d:\n digits[COSTS[d]] = d\n\n digits = [(d, c) for c, d in digits.items()]\n base_digit, base_cost = min(digits, key=lambda x: x[1])\n\n for length in range(remain // base_cost, -1, -1):\n if gen(base_digit, base_cost, length, digits, remain):\n break\n\n\nif __name__ == '__main__':\n main()\n\n"] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s016585815', 's092203647', 's171995760', 's185060034', 's300699616', 's468867807', 's599847626', 's637395430', 's817915484', 's891611101', 's925774693', 's954544783', 's984530156', 's818263631'] | [3316.0, 3444.0, 3444.0, 3316.0, 3316.0, 3444.0, 3316.0, 3444.0, 3348.0, 3444.0, 3316.0, 3444.0, 3340.0, 3444.0] | [19.0, 22.0, 19.0, 19.0, 20.0, 19.0, 19.0, 2104.0, 20.0, 20.0, 20.0, 19.0, 19.0, 20.0] | [1436, 851, 1701, 909, 1461, 1556, 903, 803, 1725, 867, 906, 1657, 899, 1733] |
p03128 | u350049649 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["match_num=[0,2,5,5,4,5,6,3,7,6]\nN,M=map(int, input().split())\nnums=sorted(list(map(int, input().split())),reverse=True)\nINF=1000000\n\ndp = [-INF for _ in range(N+1)]\ndp[0]=0\nusables=[]\nfor n in nums:\n usables.append(match_num[n])\n\nfor i in range(min(usables), N+1):\n tmp=[]\n for u in usables:\n if(i-u)>=0:\n tmp.append(dp[i-u])\n \n dp[i]=max(tmp)+1\n\nremained_maches=N\n\nans='' \nfor i in range(dp[N]):\n for j in range(M):\n if dp[remained_maches]-1==dp[remained_maches-usables[j]]:\n ans+=str(nums[j])\n remained_maches-=usables[j]\n break\n\nprint(dp)\nprint(ans)\n\n", 'c=[0,2,5,5,4,5,6,3,7,6]\nN,M=map(int, input().split())\nA=list(map(int, input().split()))\nINF=100010\ndp = [-INF for _ in range(N+1)]\ndp[0]=0\n\nfor i in range(N+1):\n for a in A:\n if i-c[a]>=0:\n dp[i]=max(dp[i],(dp[i-c[a]])*10+a)\n\nprint(dp[N])'] | ['Runtime Error', 'Accepted'] | ['s184988644', 's921870432'] | [3572.0, 14672.0] | [61.0, 158.0] | [597, 247] |
p03128 | u352558780 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['pair = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nn, m = [int(x) for x in input().split()]\ngiven = sorted([int(i) for i in input().split()])\ngiven_pair = sorted([pair[x - 1] for x in given], reverse=True)\n\ndp = (1 + n) * [0]\nmax_dp = 0\nfor i in range(n + 1):\n if i == 0:\n dp[i] = 0\n for j in range(m):\n if i - given_pair[j][1] >= 0:\n if dp[i - given_pair[j][1]] + 1 >= max_dp:\n max_dp = dp[i - given_pair[j][1]] + 1\n dp[i] = max_dp\n\n\n\ndef choice_list(x, index):\n# print("now_index", index)\n# print(given_pair[x][1])\n# print("now_dp_atai", dp[index - given_pair[x][1]])\n if dp[index - given_pair[x][1]] == dp[index] - 1:\n if dp[index - given_pair[x][1]] == 0:\n for j in given_pair:\n print(j)\n if index == j[1]:\n return str(j[0])\n return ""\n elif index - given_pair[x][1] < 0:\n return "-1"\n else:\n return str(given_pair[x][0]) + choice_list(x, index - given_pair[x][1])\n\n else:\n return choice_list(x + 1, index)\n\n\nprint(choice_list(0, n))', 'pair = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nn,m =[int(x) for x in input().split()]\ngiven = sorted([int(i) for i in input().split()])\ngiven_pair = sorted([pair[x-1] for x in given],key = lambda x :x[1])\ndef rec(n,t_list,pair_list):\n if n==0:\n return t_list\n elif n< pair_list[0][1]:\n return t_list[:-1]\n else:\n a = rec(n-pair_list[0][1],t_list+[pair_list[0][0]],pair_list)\n if pair_list[1:]!=[]:\n b = rec(n,t_list,pair_list[1:])\n if len(a)>len(b):\n return a\n elif len(a)==len(b):\n if(a[-1]>b[-1]):\n return a\n else:\n return b\n else:\n return b\n else:\n return a\n\nkotae = map(str,sorted(rec(n,[],given_pair),reverse=True))\nprint("".join(kotae))', 'pair = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nn, m = [int(x) for x in input().split()]\ngiven = sorted([int(i) for i in input().split()])\ngiven_pair = sorted([pair[x - 1] for x in given], reverse=True)\n\ndp = (1 + n) * [0]\nmax_dp = 0\nfor i in range(n + 1):\n if i == 0:\n dp[i] = 0\n for j in range(m):\n if i - given_pair[j][1] >= 0:\n if dp[i - given_pair[j][1]] + 1 >= max_dp:\n max_dp = dp[i - given_pair[j][1]] + 1\n dp[i] = max_dp\n\nprint(given_pair)\n\nprint(dp)\n\n\ndef choice_list(x, index):\n# print("now_index", index)\n# print(given_pair[x][1])\n# print("now_dp_atai", dp[index - given_pair[x][1]])\n if dp[index - given_pair[x][1]] == dp[index] - 1:\n if dp[index - given_pair[x][1]] == 0:\n for j in given_pair:\n print(j)\n if index == j[1]:\n return str(j[0])\n return ""\n elif index - given_pair[x][1] < 0:\n return "-1"\n else:\n return str(given_pair[x][0]) + choice_list(x, index - given_pair[x][1])\n\n else:\n return choice_list(x + 1, index)\n\n\nprint(choice_list(0, n))', 'pair = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nn,m =[int(x) for x in input().split()]\ngiven = sorted([int(i) for i in input().split()])\ngiven_pair = sorted([pair[x-1] for x in given],key = lambda x :x[1])\ndef rec(n,t_list,pair_list):\n if n==0:\n return t_list\n elif n< pair_list[0][1]:\n return t_list[:-1]\n else:\n a = rec(n-pair_list[0][1],t_list+[pair_list[0][0]],pair_list)\n if pair_list[1:]!=[]:\n b = rec(n,t_list,pair_list[1:])\n if len(a)>len(b):\n return a\n elif len(a)==len(b):\n if(a[-1]>=b[-1]):\n return a\n else:\n return b\n else:\n return b\n else:\n return a\n\nkotae = map(str,sorted(rec(n,[],given_pair),reverse=True))\nprint("".join(kotae))\n', 'n,m = [int(i) for i in input().split()]\ne = [[int(i) for i in input().split()] for i in range(n)]\n\ns=[]\nfor t in e:\n b_list=0\n for x in t[1:]:\n b_list = b_list | pow(2,x-1)\n s.append(b_list)\nresult=pow(2,30)-1\nfor i in s:\n result = result & i\ncnt=0\nfor i in range(30):\n if result & pow(2,i):\n cnt+=1\nprint(cnt)', 'n, m = [int(i) for i in input().split()]\nam = sorted([int(i) for i in input().split()],reverse=True)\nc = [2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndp = [0 for i in range(n+1)]\n\nfor i in range(n+1):\n max_tmp = -float("inf")\n for j in am:\n if i-c[j-1]>=0:\n max_tmp = max(dp[i-c[j-1]]+1, max_tmp)\n dp[i] = max(dp[i],max_tmp)\n\ntmp_n = n\nans =[]\nfor i in range(dp[n]):\n for j in range(m):\n if i==dp[n]-1 and tmp_n- c[am[j]-1] != 0:\n continue\n if tmp_n - c[am[j]-1] >= 0 and dp[tmp_n - c[am[j]-1]] == dp[tmp_n] -1:\n ans.append(am[j])\n tmp_n -= c[am[j]-1]\n break\n\n\nprint(ans)', 'pair = [[1, 2], [2, 5], [3, 5], [4, 4], [5, 5], [6, 6], [7, 3], [8, 7], [9, 6]]\nn, m = [int(x) for x in input().split()]\ngiven = sorted([int(i) for i in input().split()])\ngiven_pair = sorted([pair[x - 1] for x in given], reverse=True)\n\ndp = (1 + n) * [0]\nmax_dp = 0\nfor i in range(n + 1):\n if i == 0:\n dp[i] = 0\n for j in range(m):\n if i - given_pair[j][1] >= 0:\n if dp[i - given_pair[j][1]] + 1 >= max_dp:\n max_dp = dp[i - given_pair[j][1]] + 1\n dp[i] = max_dp\n\nprint(given_pair)\n\nprint(dp)\n\n\ndef choice_list(x, index):\n# print("now_index", index)\n# print(given_pair[x][1])\n# print("now_dp_atai", dp[index - given_pair[x][1]])\n if dp[index - given_pair[x][1]] == dp[index] - 1:\n if dp[index - given_pair[x][1]] == 0:\n for j in given_pair:\n if index == j[1]:\n return str(j[0])\n return ""\n elif index - given_pair[x][1] < 0:\n return "-1"\n else:\n return str(given_pair[x][0]) + choice_list(x, index - given_pair[x][1])\n\n else:\n return choice_list(x + 1, index)\n\n\nprint(choice_list(0, n))', 'n, m = [int(i) for i in input().split()]\nam = sorted([int(i) for i in input().split()],reverse=True)\nc = [2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndp = [-1 for i in range(n+1)]\ndp[0]=0\nfor i in range(n+1):\n #max_tmp = -float("inf")\n for j in am:\n if i+c[j-1]<=n:\n dp[i+c[j-1]] = max(dp[i+c[j-1]], dp[i]+1)\n#print(dp)\ntmp_n = n\nans =""\nfor i in range(dp[n]):\n for j in range(m):\n if i==dp[n]-1 and tmp_n- c[am[j]-1] != 0:\n continue\n if tmp_n - c[am[j]-1] >= 0 and dp[tmp_n - c[am[j]-1]] == dp[tmp_n] -1:\n ans+=(str(am[j]))\n tmp_n -= c[am[j]-1]\n break\n\n\nprint(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s063008825', 's091188668', 's095517376', 's110391019', 's142619817', 's527509468', 's538827541', 's124935542'] | [4308.0, 8948.0, 4476.0, 8016.0, 3064.0, 3432.0, 4500.0, 3392.0] | [118.0, 2108.0, 118.0, 2104.0, 17.0, 97.0, 123.0, 104.0] | [1151, 817, 1180, 819, 322, 643, 1155, 634] |
p03128 | u360116509 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n\ndef main():\n N, M = map(int, input().split())\n A = list(map(int, input().split()))\n dp = [-1 for _ in range(N + 1)]\n dp[0] = 0\n for i in range(1, N + 1):\n for a in A:\n if i < costs[a - 1]:\n continue\n dp[i] = max(dp[i], dp[i - costs[a - 1]] * 10 + a)\n print(dp)\n\n\nmain()\n', 'costs = [2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n\ndef main():\n N, M = map(int, input().split())\n A = list(map(int, input().split()))\n dp = [-1 for _ in range(N + 1)]\n dp[0] = 0\n for i in range(1, N + 1):\n for a in A:\n if i < costs[a - 1]:\n continue\n dp[i] = max(dp[i], dp[i - costs[a - 1]] * 10 + a)\n print(dp[N])\n\n\nmain()\n'] | ['Wrong Answer', 'Accepted'] | ['s802781416', 's441986047'] | [87840.0, 14388.0] | [1503.0, 130.0] | [370, 373] |
p03128 | u368780724 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["def inpl(): return list(map(int, input().split()))\n\nN, M = inpl()\nA = inpl()\nA.sort(reverse = True)\n\ninf = float('inf')\nmatch = (inf, 2, 5, 5, 4, 5, 6, 3, 7, 6)\nmatnum = set([match[a] for a in A])\ndp = [0]+[-inf]*N\n\nfor i in range(1, N+1):\n dp[i] = max([10*dp[i-a] + a for a in A])\n\nprint(''.join(sorted(str(dp[-1]), reverse = True)))\n", "def inpl(): return list(map(int, input().split()))\n\nN, M = inpl()\nA = inpl()\nA.sort(reverse = True)\n\nmatch = (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)\ndp = [0]+[float('inf')]*N\n\nfor i in range(1, N+1):\n dp[i] = max([10*dp[max(-1,i-match[a])] + a for a in A])\n\nprint(''.join(sorted(str(dp[-1]), reverse = True)))\n", "def inpl(): return list(map(int, input().split()))\n\nN, M = inpl()\nA = inpl()\nA.sort(reverse = True)\n\nmatch = (0, 2, 5, 5, 4, 5, 6, 3, 7, 6)\ndp = [0]+[-float('inf')]*N\n\nfor i in range(1, N+1):\n dp[i] = max([10*dp[max(-1,i-match[a])] + a for a in A])\n\nprint(''.join(sorted(str(dp[-1]), reverse = True)))\n"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s060357796', 's875383142', 's523600556'] | [26356.0, 3700.0, 14964.0] | [190.0, 61.0, 139.0] | [338, 304, 305] |
p03128 | u368796742 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m = map(int,input().split())\na = list(map(int,input().split()))\na.sort(reverse = True)\nl = [0,2,5,5,4,5,6,3,7,6]\nINF = 10**18\ndp = [[[-INF]*2 for i in range(n+1)] for j in range(m+1)]\ndp[0][0] = [0,0]\nfor i in range(m):\n for j in range(n+1):\n x = l[a[i]]\n dp[i+1][j] = dp[i][j]\n if x <= j:\n if dp[i+1][j-x][0] > -INF:\n a1 = dp[i+1][j-x][0] +1\n a2 = dp[i+1][j-x][1] + a[i]\n if a1 > dp[i][j][0]:\n dp[i+1][j] = [a1,a2]\n elif a1 == dp[i][j][0] and a2 > dp[i][j][1]:\n dp[i+1][j] = [a1,a2]\n\nans = []\nna = dp[-1][-1][0]\nnb = dp[-1][-1][1]\na.sort()\nfor i in range(m,0,-1):\n for j in range(n,-1,-1):\n x = l[a[i-1]]\n if dp[i][j] == [na-1,nb-a[i-1]]:\n na -= 1\n nb -= a[i-1]\n ans.append(a[i-1])\n\nans.sort(reverse = True)\nprint(*ans,sep="")', 'n,m = map(int,input().split())\na = list(map(int,input().split()))\na.sort(reverse = True)\nl = [0,2,5,5,4,5,6,3,7,6]\n\ndp = [-1**10]*(n+1)\ndp[0] = 0\nfor i in range(1,n+1):\n \n for j in range(m):\n if i >= l[a[j]] and dp[i] < dp[i-l[a[j]]]+1:\n dp[i] = dp[i-l[a[j]]]+1\n \n\nans = []\nremain = dp[-1]\nnow = n\nfor i in a:\n x = l[i]\n while now -x >= 0 and dp[now] == dp[now-x]+1:\n ans.append(i)\n now -= x \nprint(*ans,sep="")'] | ['Wrong Answer', 'Accepted'] | ['s461425131', 's719341335'] | [16756.0, 4324.0] | [217.0, 68.0] | [912, 466] |
p03128 | u375616706 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA = sorted(A, reverse=True)\n\nnums = {}\nnums[1] = 2\nnums[2] = 5\nnums[3] = 5\nnums[4] = 4\nnums[5] = 5\nnums[6] = 6\nnums[7] = 3\nnums[8] = 7\nnums[9] = 6\n\ndp = [0]*(N+1)\n\nfor i in range(1, N+1):\n make = True\n for a in A:\n if i-nums[a] >= 0:\n dp[i] = max(1, dp[i-nums[a]]+1)\n make = False\n if make:\n dp[i] = -float(\'inf\')\n\nans = ""\ni = N\nwhile i > 0:\n for a in A:\n if dp[i]-1 == dp[i-nums[a]]:\n ans += str(a)\n i = i-nums[a]\n break\nprint(ans)\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA = sorted(A, reverse=True)\n\nnums = {}\nnums[1] = 2\nnums[2] = 5\nnums[3] = 5\nnums[4] = 4\nnums[5] = 5\nnums[6] = 6\nnums[7] = 3\nnums[8] = 7\nnums[9] = 6\n\ndp = [0]*(N+1)\n\nfor i in range(1, N+1):\n make = True\n for a in A:\n if i-a >= 0:\n dp[i] = max(1, dp[i-nums[a]]+1)\n make = False\n if make:\n dp[i] = -float(\'inf\')\n\nans = ""\ni = N\nwhile i > 0:\n for a in A:\n if dp[i]-1 == dp[i-nums[a]]:\n ans += str(a)\n i = i-nums[a]\n break\nprint(ans)\n', '# python template for atcoder1\nimport sys\nsys.setrecursionlimit(10**9)\ninput = sys.stdin.readline\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nA = sorted(A, reverse=True)\n\nnums = {}\nnums[1] = 2\nnums[2] = 5\nnums[3] = 5\nnums[4] = 4\nnums[5] = 5\nnums[6] = 6\nnums[7] = 3\nnums[8] = 7\nnums[9] = 6\n\ndp = [-float(\'inf\')]*(N+1)\ndp[0] = 0\n\nfor i in range(N+1):\n for a in A:\n if i-nums[a] >= 0:\n dp[i] = max(dp[i], dp[i-nums[a]]+1)\n\nans = ""\ni = N\nwhile i > 0:\n for a in A:\n if i >= nums[a] and dp[i]-1 == dp[i-nums[a]]:\n ans += str(a)\n i = i-nums[a]\n break\nprint(ans)\n'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s757171687', 's862478309', 's832680040'] | [3396.0, 3396.0, 3424.0] | [2104.0, 2104.0, 88.0] | [689, 683, 645] |
p03128 | u391731808 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N,M = map(int,input().split())\n*A, = map(int,input().split())\nB = sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1]))\ni = 1\nwhile i<len(B):\n if B[i][0]==B[i-1][0]:\n B.pop(i)\n else:\n i+=1\ni = [0]*(len(B)-1)\nans_tmp = (0,[])\nwhile i[-1]<B[0][0]:\n tmp = N - sum(j*b[0] for j,b in zip(i,B[1:]))\n if tmp%B[0][0] == 0:\n tmp2 = tmp//B[0][0] + sum(j for j in i)\n if ans_tmp[0] < tmp2:\n ans_tmp = (tmp2,[tmp//B[0][0]]+i)\n i[0]+=1\n for j in range(len(i)-1):\n if i[j]==B[0][0]:\n i[j+1]+=1\n i[j]=0\nans = ""\nfor i,n in sorted(zip([b for _,b in B],ans_tmp[1]),key=lambda x:-x[0]):\n ans += str(i)*n\nprint(ans)', 'N,M = map(int,(input().split()))\nA = list(map(int,input().split()))\ncost = sorted(list(zip([[2,5,5,4,5,6,3,7,6][a-1] for a in A],A)),key = lambda x: (x[0],-x[1]))\n\n\ntmp = len(cost)\ni = 1\nwhile i < tmp:\n if cost[i][0] == cost[i-1][0]:\n cost.pop(i)\n tmp = len(cost)\n else:\n i += 1\ncost.sort(key = lambda x:-x[1])\n\ndp = [0]*(N+1)\nfor i in range(2,N+1):\n dp[i] = max([0]+[dp[i-a]+1 for a,_ in cost if i >= a])\n\nn = N\nout = ""\ni = 0\nwhile n:\n c , a = cost[i]\n if dp[n-c] ==dp[n]-1:\n n -= c\n out += str(a)\n else:\n i+=1\nprint(out)', 'N,M = map(int,input().split())\n*A, = map(int,input().split())\nB = sorted((([2,5,5,4,5,6,3,7,6][a-1],a) for a in A),key = lambda x:(x[0],-x[1]))\ni = 1\nwhile i<len(B):\n if B[i][0]==B[i-1][0]:\n B.pop(i)\n else:\n i+=1\ni = [0]*(len(B)-1)\nif len(B)==1:\n print(str(B[0][1])*(N//B[0][0]))\n exit()\nans = []\nwhile i[-1]<B[0][0]:\n tmp = N - sum(j*b[0] for j,b in zip(i,B[1:]))\n if tmp>=0 and tmp%B[0][0] == 0:\n num = ""\n for k,n in sorted(zip([b for _,b in B],[tmp//B[0][0]]+i),key = lambda x:-x[0]):\n num += str(k)*n\n ans.append(int(num))\n i[0]+=1\n for j in range(len(i)-1):\n if i[j]==B[0][0]:\n i[j+1]+=1\n i[j]=0\nprint(max(ans))'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s900447096', 's955975297', 's495858597'] | [3192.0, 3312.0, 3188.0] | [18.0, 37.0, 21.0] | [709, 614, 716] |
p03128 | u392319141 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["from bisect import bisect_left\nN, M = map(int, input().split())\nnums = list(map(int, input().split()))\nnums.sort(reverse=True)\n\nmatchNum = {\n 1 : 2,\n 2 : 5,\n 3 : 5,\n 4 : 4,\n 5 : 5,\n 6 : 6,\n 7 : 3,\n 8 : 7,\n 9 : 6,\n}\n\nmakeDigit = [0] * (N + 1)\nfor n in range(1, N + 1):\n d = makeDigit[n]\n for k in nums:\n cnt = n - matchNum[k]\n if cnt >= 0:\n d = max(d, makeDigit[cnt] + 1)\n if makeDigit[n] < d:\n makeDigit[n] = d\n\nans = []\nfor d in range(makeDigit[N])[:: -1]:\n for k in nums:\n cnt = N - matchNum[k]\n if makeDigit[cnt] == d:\n ans.append(k)\n N = cnt\n break\n\nans.sort(reverse=True)\nprint(int(''.join(map(str, ans))))\n\n", "from bisect import bisect_left\nN, M = map(int, input().split())\nnums = list(map(int, input().split()))\n\nmatchNum = {\n 1 : 2,\n 2 : 5,\n 3 : 5,\n 4 : 4,\n 5 : 5,\n 6 : 6,\n 7 : 3,\n 8 : 7,\n 9 : 6,\n}\n\ndp = [''] * (N + 1)\nfor n in range(1, N + 1):\n for k in nums:\n d = 0\n cnt = n - matchNum[k]\n if cnt >= 0 and (dp[cnt] != '' or (cnt == 0 and dp[n] <= dp[cnt] * 10)):\n oldVal = list(str(dp[cnt]))[:: -1]\n adder = bisect_left(oldVal, str(k))\n newVal = oldVal[:adder] + [str(k)] + oldVal[adder:]\n newVal = int(''.join(newVal[:: -1]))\n d = max(d, newVal)\n if d == 0:\n continue\n elif dp[n] == '':\n dp[n] = d\n else:\n dp[n] = max(dp[n], d)\n\nprint(dp[N])", "N, M = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort(reverse=True)\n\nmatch = [10**18, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n\ndp = [-10**18] * (N + 1)\ndp[0] = 1\n\nfor i in range(N):\n for a in A:\n m = match[a]\n if i + m <= N and dp[i + m] < dp[i] + 1:\n dp[i + m] = dp[i] + 1\n\nans = []\nwhile N > 0:\n for a in A:\n m = match[a]\n if N - m >= 0 and dp[N - m] + 1 == dp[N]:\n ans.append(a)\n N -= m\n break\n\nans.sort(reverse=True)\n\nprint(''.join(map(str, ans)))\n"] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s618637638', 's849594095', 's132237370'] | [3696.0, 8436.0, 3680.0] | [72.0, 2104.0, 75.0] | [731, 797, 566] |
p03128 | u393512980 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import sys\nsys.setrecursionlimit(100001)\ndef input():\n return sys.stdin.readline()[:-1]\nimport copy\n\nN, M = map(int, input().split())\nA = sorted(list(map(int, input().split())), reverse = True)\nx = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = [0 for i in range(N+1)]\ncnt = [[0] * 10 for i in range(N+1)]\nfor i in range(2, N+1):\n for a in A:\n if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:\n dp[i] = dp[i-x[a]] + 1\n cnt[i] = copy.copy(cnt[i-x[a]])\n cnt[i][a] += 1\nans = ''\nfor i in range(9):\n ans += str(9-i) * cnt[N][9-i]\nprint(ans)", "import sys\nsys.setrecursionlimit(100001)\ndef input():\n return sys.stdin.readline()[:-1]\nimport copy\n\nN, M = map(int, input().split())\nA = sorted(list(map(int, input().split())), reverse = True)\nx = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = [0 for i in range(N+1)]\ncnt = [[0] * 10 for i in range(N+1)]\nfor i in range(2, N+1):\n for a in A:\n if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:\n dp[i] = dp[i-x[a]] + 1\n cnt[i] = copy.copy(cnt[i-x[a]])\n cnt[i][a] += 1\nprint(cnt)\nans = ''\nfor i in range(9):\n ans += str(9-i) * cnt[N][9-i]\nprint(ans)", "import sys\nsys.setrecursionlimit(100001)\ndef input():\n return sys.stdin.readline()[:-1]\n \nN, M = map(int, input().split())\nA = sorted(list(map(int, input().split())), reverse = True)\nx = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = [0 for i in range(N+1)]\nfor i in range(2, N+1):\n for a in A:\n if i >= x[a] and dp[i-x[a]] + 1 > dp[i]:\n dp[i] = dp[i-x[a]] + 1\nK = N\nans = ''\nwhile K > 0:\n for a in A:\n if dp[K] == dp[K-x[a]] + 1:\n ans += str(a)\n K -= x[a]\n break\nprint(ans)", 'N, M = map(int, input().split())\nA = sorted(list(map(int, input().split())), reverse = True)\nx = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = [0 for i in range(N+1)]\nINF = float(\'inf\')\nfor i in range(1, N+1):\n t = -INF\n for a in A:\n if i >= x[a]:\n t = max(dp[i-x[a]] + 1, t)\n dp[i] = t\n\nK = N\nk = dp[N]\nans = ""\nwhile k > 0:\n for a in A:\n xa = x[a]\n if K >= xa and k == dp[K-xa] + 1:\n ans += str(a)\n K -= xa\n k -= 1\n break\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s533356977', 's908458926', 's963363804', 's895593689'] | [6308.0, 7496.0, 3424.0, 3336.0] | [92.0, 103.0, 2104.0, 82.0] | [565, 576, 533, 512] |
p03128 | u413165887 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["n , m = map(int, input().split(' '))\ns = [0,2,5,5,4,5,6,3,7,6]\na = list(map(int, input().split(' ')))\na.sort()\nd = [0]\nfor i in range(n):\n d.append(-1)\n\nfor i in range(n+1):\n j = 0\n while j < len(a):\n if d[i-s[a[j]]] >= 0:\n d[i] = d[i-s[a[j]]] +1\n break\n else:\n j+= 1\nresult = []\na.sort(reverse = True)\nwhile n > 0:\n j = 0\n while j < len(a):\n if d[n-s[a[j]]] +1 == d[n]:\n result.append(a[j])\n n -= s[a[j]]\n else:\n j += 1 \nprint(''.join(list(map(str, result))))", "n , m = map(int, input().split(' '))\ns = [0,2,5,5,4,5,6,3,7,6]\na = list(map(int, input().split(' ')))\nr = []\nfor i in range(len(a)):\n r.append([s[a[i]],a[i]])\nr.sort()\nd = [0]\nfor i in range(n+10):\n d.append(-1)\nfor i in range(n+1):\n j = 0\n while j < len(a):\n if i-s[r[j][1]] < 0:\n j += 1\n elif d[i-s[r[j][1]]] >= 0:\n d[i] = d[i-s[r[j][1]]] +1\n break\n else:\n j+= 1\nresult = []\na.sort(reverse = True)\nwhile n > 0:\n j = 0\n while j < len(a):\n if d[n-s[a[j]]] +1 == d[n]:\n result.append(a[j])\n n -= s[a[j]]\n else:\n j += 1\n \nprint(''.join(list(map(str, result))))\n\n\n", "def main():\n n, m = map(int, input().split(' '))\n a = list(map(int, input().split(' ')))\n b = [0,2,5,5,4,5,6,3,7,6]\n c = [[b[i], -i] for i in a]\n c.sort()\n result = [[] for _ in range(n+1)]\n dp = [-1]*(n+1)\n dp[0] = 0\n for i in range(1, n+1):\n for j in c:\n if i-j[0] >= 0:\n if dp[i-j[0]] >= 0:\n dp[i] = dp[i-j[0]] +1\n break\n c = [[-x[1], x[0]] for x in c]\n c.sort(reverse = True)\n result = []\n i = n\n while i > 0:\n j = 0\n while j < len(c):\n if i-c[j][1] >= 0:\n if dp[i-c[j][1]] + 1 == dp[i]:\n result.append(c[j][0])\n i -= c[j][1]\n j = len(c)\n else:\n j += 1\n else:\n j += 1\n print(''.join(map(str, result)))\nif __name__ =='__main__':\n main()"] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s516483893', 's882132038', 's704529108'] | [3700.0, 3700.0, 4084.0] | [28.0, 29.0, 38.0] | [603, 702, 915] |
p03128 | u426108351 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\nmatchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nnumberlist = []\nfor i in range(M):\n numberlist.append([matchlist[A[i]], A[i]])\nnumberlist.sort(key = lambda x: (x[0], -x[1]))\n\nans = []\nwhile N > 0:\n print(N)\n ans.append(numberlist[0])\n N -= ans[-1][0]\n if N < 0:\n N += ans.pop()[0]\n N += ans.pop()[0]\n numberlist.pop(0)\n\nans = [i[1] for i in ans]\nans.sort(reverse = True)\nprint("".join(map(str, ans)))\n', 'n, m = map(int, input().split())\na = list(map(int, input().split()))\nmatchlist = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nnumberlist = []\nfor i in range(m):\n numberlist.append(matchlist[a[i]])\nnumberlist = set(numberlist)\n\ndp = [-10000000]*(n+1)\ndp[0] = 0\nfor i in range(n):\n for j in numberlist:\n if i+j <= n:\n dp[i+j] = max(dp[i+j], dp[i]+1)\n\n\nans = []\nd = dp[n]\na.sort(reverse = True)\nfor i in range(d):\n for j in a:\n if n - matchlist[j] >= 0:\n if dp[n] == dp[n-matchlist[j]] + 1:\n n -= matchlist[j]\n ans.append(j)\n break\nprint("".join(map(str,ans)))\n'] | ['Runtime Error', 'Accepted'] | ['s561757897', 's563337229'] | [3700.0, 3696.0] | [23.0, 73.0] | [501, 657] |
p03128 | u440161695 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['解説放送の1つめ\nN,M = map(int, input().split())\nA = list(map(int, input().split()))\nf = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed\n \n\ndp = [None]*(N+1)\ndp[0] = ""\n \n\ndef max_str(s1:str, s2:str)->str:\n """return bigger one"""\n l1, l2 = len(s1), len(s2)\n if l1 != l2:\n return s1 if l1>l2 else s2\n if l1 == l2: \n return s1 if s1>s2 else s2\n \nfor i in range(2, N+1):\n nxt = ""\n for aj in A:\n \n if i-f[aj]<0 or dp[i-f[aj]]==None: continue\n nxt = max_str(nxt, \n dp[i-f[aj]]+str(aj))\n if nxt!="":\n dp[i] = nxt\n #print(dp)\nprint(dp[N])', '\nN,M = map(int, input().split())\nA = list(map(int, input().split()))\nA.sort(reverse=True)\nf = [-1, 2,5,5,4,5,6,3,7,6] # 1-indexed\n\n\ndp = [-float(\'inf\')]*(N+1)\ndp[0] = 0\nfor i in range(N+1):\n nxt = dp[i]\n for aj in A:\n if i-f[aj]<0: continue\n nxt = max(nxt, \n dp[i-f[aj]] + 1)\n dp[i] = nxt\n #print(dp)\n#print(dp[N])\nketa = dp[N]\nans = ""\nmatchs = N\n\nwhile keta>0:\n for aj in A:\n if matchs-f[aj] < 0: continue\n if dp[matchs-f[aj]] == keta-1:\n ans += str(aj)\n matchs -= f[aj]\n keta -= 1\n break\nprint(ans)\n'] | ['Runtime Error', 'Accepted'] | ['s078445653', 's806372580'] | [3064.0, 3356.0] | [17.0, 83.0] | [771, 726] |
p03128 | u451017206 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["N, M = map(int, input().split())\nA = [i for i in input().split()]\n\n\n\ndef mx(a, b):\n if len(a) != len(b):\n if len(a) > len(b):\n return a\n else:\n return b\n return max(a, b)\n\n\nh = {'1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6}\n\n\ndp = [''] * (N + 1)\ndp[0] = ' '\n\nfor i in range(N + 1):\n for a in A:\n if i - h[a] < 0: continue\n dp[i] = mx(dp[i-h[a]] + a, dp[i])\n\nprint(dp[N])", "N, M = map(int, input().split())\nA = [i for i in input().split()]\n\n\n\ndef mx(a, b):\n if len(a) != len(b):\n if len(a) > len(b):\n return a\n else:\n return b\n return max(a, b)\n\n\nh = {'1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6}\n\ndp = [None] * (N + 1)\ndp[0] = ''\n\nfor i in range(N + 1):\n for a in A:\n if i - h[a] < 0: continue\n try:\n dp[i] = mx(dp[i-h[a]] + a, dp[i])\n except:\n continue\n\nprint(dp[N])", "N, M = map(int, input().split())\nA = sorted([i for i in input().split()], reverse=True)\n\n\n\ndef mx(a, b):\n if len(a) != len(b):\n if len(a) > len(b):\n return a\n else:\n return b\n return max(a, b)\n\n\nh = {'1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6}\n\ndp = [''] * (N + 1)\ndp[0] = ' '\n\nfor i in range(N + 1):\n for a in A:\n if i - h[a] < 0: continue\n dp[i] = mx(dp[i-h[a]] + a, dp[i])\n\nprint(dp[N])", "N, M = map(int, input().split())\nA = sorted([i for i in input().split()], reverse=True)\n\n\n\ndef mx(a, b):\n if len(a) != len(b):\n if len(a) > len(b):\n return a\n else:\n return b\n if a >= b:\n return a\n else:\n return b\n\nh = {'1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6}\n\n\ndef f(x):\n return h[x]\n\ndp = [''] * (N + 1)\ndp[0] = ' '\n\nfor i in range(N+1):\n for a in A:\n if i - f(a) < 0:\n continue\n dp[i] = mx(dp[i-f(a)] + a, dp[i])\nprint(dp[N])", "N, M = map(int, input().split())\nA = sorted([int(i) for i in input().split()], reverse=True)\n\n\nh = {1:2, 2:5, 3:5, 4:4, 5:5, 6:6, 7:3, 8:7, 9:6}\n\n\ndp = [-1] * (N + 1)\ndp[0] = 0\n\nfor i in range(N + 1):\n for a in A:\n if i - h[a] < 0: continue\n dp[i] = max(dp[i-h[a]] + 1, dp[i])\n\ndigit = dp[N]\nans = ''\n\nn = N\nfor d in range(digit):\n for a in A:\n if n - h[a] < 0:continue\n if dp[n - h[a]] == digit - 1:\n ans += str(a)\n n -= h[a]\n digit -= 1\n break\nprint(ans)"] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s068170755', 's265593534', 's712680191', 's815345886', 's555594210'] | [28120.0, 3064.0, 29680.0, 29680.0, 3388.0] | [117.0, 95.0, 122.0, 134.0, 91.0] | [535, 589, 556, 630, 678] |
p03128 | u456353530 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['\nimport copy\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nL = {}\nfor i in A:\n if t[i] in L:\n if L[t[i]] < i:\n L[t[i]] = i\n else:\n L[t[i]] = i', 'import copy\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nL = {}\nfor i in A:\n if t[i] in L:\n if L[t[i]] < i:\n L[t[i]] = i\n else:\n L[t[i]] = i\n \ndp = [[0 for j in range(10)] for i in range(N)]\nja = [0 for j in range(10)]\nfor i in L.items():\n dp[i[0] - 1][i[1]] = 1\nfor i in range(N):\n if dp[i] == ja:\n continue\n for j in L.items():\n k = i + j[0]\n if k < N:\n t = copy.deepcopy(dp[i])\n t[j[1]] += 1\n for ii in range(9, 0, -1):\n if t[ii] > dp[k][ii]:\n dp[k] = t\n break\n elif t[ii] < dp[k][ii]:\n break\n \nt = dp[-1]\nAns = ""\nfor i in range(9, 0, -1):\n for k in range(t[i]):\n Ans += str(i)\n \nprint(Ans)', '\nimport copy\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nL = {}\nfor i in A:\n if t[i] in L:\n if L[t[i]] < i:\n L[t[i]] = i\n else:\n L[t[i]] = i\n\ndp = [[0 for j in range(10)] for i in range(N)]', '\nimport copy\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nL = {}\nfor i in A:\n if t[i] in L:\n if L[t[i]] < i:\n L[t[i]] = i\n else:\n L[t[i]] = i\n\ndp = [[0 for j in range(10)] for i in range(N)]\nfor i in L.items():\n dp[i[0] - 1][i[1]] = 1\nfor i in range(N):\n if max(dp[i]) == 0:\n continue\n for j in L.items():\n k = i + j[0]\n if k < N:\n t = copy.deepcopy(dp[i])\n t[j[1]] += 1\n if sum(t) > sum(dp[k]):\n dp[k] = t\n else:\n for ii in range(9, 0, -1):\n if t[ii] > dp[k][ii]:\n dp[k] = t\n break\n elif t[ii] < dp[k][ii]:\n break', '\nimport copy\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nL = {}\nfor i in A:\n if t[i] in L:\n if L[t[i]] < i:\n L[t[i]] = i\n else:\n L[t[i]] = i\n\ndp = [[0 for j in range(10)] for i in range(N)]\nfor i in L.items():\n dp[i[0] - 1][i[1]] = 1', 'import copy\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nL = {}\nfor i in A:\n if t[i] in L:\n if L[t[i]] < i:\n L[t[i]] = i\n else:\n L[t[i]] = i\n\ndp = [[0 for j in range(10)] for i in range(N)]\nfor i in L.items():\n if i[0] - 1 < N:\n dp[i[0] - 1][i[1]] = 1\nfor i in range(N):\n if max(dp[i]) == 0:\n continue\n for j in L.items():\n k = i + j[0]\n if k < N:\n t = copy.deepcopy(dp[i])\n t[j[1]] += 1\n if sum(t) > sum(dp[k]):\n dp[k] = t\n else:\n for ii in range(9, 0, -1):\n if t[ii] > dp[k][ii]:\n dp[k] = t\n break\n elif t[ii] < dp[k][ii]:\n break\n \nt = dp[-1]\nAns = ""\nfor i in range(9, 0, -1):\n for j in range(t[i]):\n Ans += str(i)\n \nprint(Ans)'] | ['Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s016841917', 's480610684', 's594927570', 's765023346', 's871966773', 's474539931'] | [3444.0, 5920.0, 5620.0, 5748.0, 5620.0, 5748.0] | [22.0, 715.0, 33.0, 720.0, 35.0, 724.0] | [243, 759, 292, 713, 337, 826] |
p03128 | u464397170 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\nsys.setrecursionlimit(100000)\n\nN, M = map(int, input().split())\nnumbers = list(map(int, input().split()))\ncosts = [2,5,5,4,5,6,3,7,6] # <- 1,2,3,4,5,6,7,8,9\ncostmap = {}\nfor num in numbers:\n cost = costs[num-1]\n if cost in costmap and num < costmap[cost]:\n continue\n costmap[cost] = num\n\nfrom functools import lru_cache\n@lru_cache(None)\ndef recursive(remain=N):\n maxval = costmap[remain] if remain in costmap else 0\n for cost, num in costmap.items():\n if remain > cost:\n val = recursive(remain-cost) * 10 + num\n if val > maxval:\n maxval = val\n return maxval\n \nprint(recursive(N))', 'import sys\nsys.setrecursionlimit(100000)\n\nN, M = map(int, input().split())\nnumbers = list(map(int, input().split()))\ncosts = [2,5,5,4,5,6,3,7,6] # <- 1,2,3,4,5,6,7,8,9\ncostmap = {}\nfor num in numbers:\n cost = costs[num-1]\n if cost in costmap and num < costmap[cost]:\n continue\n costmap[cost] = num\n\nfrom functools import lru_cache\n@lru_cache(None)\ndef recursive(remain=N):\n maxval = costmap[remain] if remain in costmap else 0\n for cost, num in costmap.items():\n if remain > cost:\n val = recursive(remain-cost)\n if val == 0:\n continue\n val = val * 10 + num\n if val > maxval:\n maxval = val\n return maxval\n \nprint(recursive(N))'] | ['Wrong Answer', 'Accepted'] | ['s788794265', 's994154716'] | [25060.0, 25060.0] | [157.0, 163.0] | [619, 671] |
p03128 | u466331465 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import fractions\nN = int(input())\nA = [int(x) for x in input().split()]\na = A[0]\nfor i in range(1,N):\n a =fractions.gcd(a,A[i])\nprint(a)', 'N,M= map(int,input().split())\n\nA = list(map(int,input().split()))\nsorted(A)\nB =[0,2,5,5,4,5,6,3,7,6]\nC =[]\nfor i in A:\n C.append(B[i])\ndp = [-1]*(N+1)\ndp[0] = 0\nfor i in range(N+1):\n for a in range(len(C)):\n if i+C[a]<=N and 0<=dp[i]:\n dp[i+C[a]] = max(dp[i]*10+A[a],dp[i+C[a]])\nprint(dp[-1])'] | ['Runtime Error', 'Accepted'] | ['s446730578', 's240224623'] | [5048.0, 14692.0] | [36.0, 184.0] | [137, 317] |
p03128 | u475329018 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n, m = map(int, input().split())\na = list(map(int, input().split()))\n\nmaxnum = [-1] * (n+1)\ncost = [0,2,5,5,4,5,6,3,7,6]\nmaxnum[0] = 0\nfor i in range(n+1):\n for num in a:\n if ( i+cost[num] < n+1 ):\n maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10)\n\nprint(maxnum)', 'n, m = map(int, input().split())\na = list(map(int, input().split()))\n\nmaxnum = [-1] * (n+1)\ncost = [0,2,5,5,4,5,6,3,7,6]\nmaxnum[0] = 0\nfor i in range(n+1):\n for num in a:\n if ( i+cost[num] < n+1 ):\n maxnum[i+cost[num]] = max(maxnum[i+cost[num]], num + maxnum[i]*10)\n\nprint(maxnum[n])'] | ['Wrong Answer', 'Accepted'] | ['s604641553', 's358620215'] | [88084.0, 14692.0] | [1530.0, 173.0] | [301, 304] |
p03128 | u475442247 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import numpy as np\n\n\nnmatch = np.array([0,2,5,5,4,5,6,3,7,6])\nN,M = map(int,input().split())\ndp = [-1]*(N+1) # contains the number of digits it can make\ndp[0] = 0\nff = np.array(list(map(int,input().split()))).reshape(-1,1)\nfg = nmatch[ff].reshape(-1,1)\nAtemp = np.concatenate([ff,fg],axis=1)\nprint(Atemp)\nindex0 = np.argsort(Atemp[:,0])\nindex1 = np.argsort(Atemp[:,1])\nA = Atemp[index1] #sorted by the number of matches: ascending\nprint(A)\nB = Atemp[index0]\nB = B[::-1] #sorted by the number: descending\nprint(B)\nfor i in range(1,N+1):\n \n for k in range(M):\n j = A[k,1]\n i_old = i - j \n if (i-j) < 0:\n break\n if (i-j) == 0 and dp[i] == -1:\n dp[i] = 1\n if dp[i_old] != -1 and dp[i_old]+1 > dp[i]:\n dp[i] = dp[i_old] + 1\nprint(dp)\nndigits = dp[N]\nj = N\nfinal_number = ''\nfor l in range(ndigits,0,-1):\n \n index = 0\n while True:\n temp_j = j - B[index,1]\n if dp[temp_j] + 1 == dp[j]:\n final_number += str(B[index,0])\n j = temp_j\n break\n else:\n index += 1\n if index > M:\n print('smth is wrong')\n break\nprint(int(final_number))\n", "import numpy as np\n\n\nnmatch = np.array([0,2,5,5,4,5,6,3,7,6])\nN,M = map(int,input().split())\ndp = [-1]*(N+1) # contains the number of digits it can make\ndp[0] = 0\nff = np.array(list(map(int,input().split()))).reshape(-1,1)\nfg = nmatch[ff].reshape(-1,1)\nAtemp = np.concatenate([ff,fg],axis=1)\nindex0 = np.argsort(Atemp[:,0])\nindex1 = np.argsort(Atemp[:,1])\nA = Atemp[index1] #sorted by the number of matches: ascending\nB = Atemp[index0]\nB = B[::-1] #sorted by the number: descending\nfor i in range(1,N+1):\n for k in range(M):\n j = A[k,1]\n i_old = i - j \n if (i-j) < 0:\n break\n if (i-j) == 0 and dp[i] == -1:\n dp[i] = 1\n if dp[i_old] != -1 and dp[i_old]+1 > dp[i]:\n dp[i] = dp[i_old] + 1\n#print(dp)\nndigits = dp[N]\nj = N\nfinal_number = ''\nfor l in range(ndigits,0,-1):\n index = 0\n while True:\n temp_j = j - B[index,1]\n if temp_j < 0:\n index += 1\n continue\n if dp[temp_j] + 1 == dp[j]:\n final_number += str(B[index,0])\n j = temp_j\n break\n else:\n index += 1\n if index > M:\n break\nprint(int(final_number))\n"] | ['Runtime Error', 'Accepted'] | ['s678286609', 's434027615'] | [14412.0, 22016.0] | [597.0, 1762.0] | [1271, 1223] |
p03128 | u475503988 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nnumbers = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = [0] * (N+1)\ndp[0] = 0\nfor i in range(N+1):\n for a in A:\n j = i + numbers[a]\n if j <= N:\n dp[j] = max(dp[j], dp[i]*10 + a)\nprint(dp[N])', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nnumbers = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = [-1] * (N+1)\ndp[0] = 0\nfor i in range(N+1):\n for a in A:\n j = i + numbers[a]\n if j <= N:\n dp[j] = max(dp[j], dp[i]*10 + a)\nprint(dp[N])'] | ['Wrong Answer', 'Accepted'] | ['s929903354', 's875126645'] | [14692.0, 14692.0] | [161.0, 157.0] | [281, 282] |
p03128 | u476604182 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\na = [int(i) for i in input().split()]\n\ndic = {}\ndic[1] = 2\ndic[2] = 5\ndic[3] = 5\ndic[4] = 4\ndic[5] = 5\ndic[6] = 6\ndic[7] = 3\ndic[8] = 7\ndic[9] = 6\n\nls = [-1]*8\ndp = [-1]*(N+1)\ndp[0] = 0\nfor i in a:\n j = dic[i]\n if ls[j]<i:\n ls[j] = i\n\ntag = []\nfor i in range(len(ls)):\n if ls[i]!=-1:\n tag += [i]\nfor i in range(N+1):\n for j in tag:\n s = max(dp[i+j]*10+ls[j], dp[i+j])\n\nprint(dp[N])', 'N, M = map(int, input().split())\na = [int(i) for i in input().split()]\n\ndic = {}\ndic[1] = 2\ndic[2] = 5\ndic[3] = 5\ndic[4] = 4\ndic[5] = 5\ndic[6] = 6\ndic[7] = 3\ndic[8] = 7\ndic[9] = 6\n\nls = [-1]*8\ndp = [-1]*(N+1)\ndp[0] = 0\nfor i in a:\n j = dic[i]\n if ls[j]<i:\n ls[j] = i\n\ntag = []\nfor i in range(len(ls)):\n if ls[i]!=-1:\n tag += [i]\nfor i in range(N+1):\n for j in tag:\n if i+j<=N:\n s = max(dp[i+j]*10+ls[j], dp[i+j])\n\nprint(dp[N])', 'from collections import defaultdict\nN,M,*A = map(int, open(0).read().split())\nls = [0]*10\nls[1] = 2\nls[2] = 5\nls[3] = 5\nls[4] = 4\nls[5] = 5\nls[6] = 6\nls[7] = 3\nls[8] = 7\nls[9] = 6\ndic = defaultdict(int)\nfor a in A:\n k = ls[a]\n dic[k] = max(dic[k],a)\ndp = [-1]*(N+1)\nfor k in dic.keys():\n if k>N:\n continue\n dp[k] = dic[k]\nfor i in range(N+1):\n for k in dic.keys():\n if i-k>0 and dp[i-k]!=-1:\n m = dp[i-k]*10+dic[k]\n dp[i] = max(dp[i], m)\nprint(dp[N])'] | ['Runtime Error', 'Wrong Answer', 'Accepted'] | ['s048395808', 's108390112', 's179999492'] | [3064.0, 3064.0, 14820.0] | [48.0, 57.0, 124.0] | [427, 444, 471] |
p03128 | u488401358 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["N,M=map(int,input().split())\nA=list(map(int,input().split()))\nA.sort()\nB=[[] for i in range(0,10)]\nfor i in range(0,M):\n if 1 in A:\n B[2].append(1)\n if 2 in A:\n B[5].append(2)\n if 3 in A:\n B[5].append(3)\n if 4 in A:\n B[4].append(4)\n if 5 in A:\n B[5].append(5)\n if 6 in A:\n B[6].append(6)\n if 7 in A:\n B[3].append(7)\n if 8 in A:\n B[7].append(8)\n if 9 in A:\n B[6].append(9)\n\n\ndp=['n' for i in range(0,max(10,N+1))]\nfor i in range(0,min(N+1,10)):\n if i==1:\n if 1 in A:\n dp[2]='1'\n if i==2:\n if 2 in A:\n dp[5]='2'\n if i==3:\n if 3 in A:\n dp[5]='3'\n if i==4:\n if 4 in A:\n dp[4]='4'\n if i==5:\n if 5 in A:\n dp[5]='5'\n if i==6:\n if 6 in A:\n dp[6]='6'\n if i==7:\n if 7 in A:\n dp[3]='7'\n if i==8:\n if 8 in A:\n dp[7]='8'\n if i==9:\n if 9 in A:\n dp[6]='9'\n\nif N>=4:\n if B[2]!=[]:\n dp[4]='11'\nif N>=5:\n if B[3]!=[] and dp[2]!='n':\n dp[5]='71'\nif N>=6:\n a='0'\n b='0'\n c='0'\n if B[2]!=[] and dp[4]!='n':\n a='1'+dp[4]\n if B[3]!=[]:\n b='77'\n if B[4]!=[] and dp[2]!='n':\n c='41'\n if dp[6]=='n':\n a=int(a)\n b=int(b)\n c=int(c)\n x=max(a,b,c)\n if x!=0:\n dp[6]=str(x)\n else:\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(dp[6])\n dp[6]=str(max(a,b,c,d))\n\nif N>=7:\n a='0'\n b='0'\n c='0'\n d='0'\n if B[2]!=[] and dp[5]!='n':\n a='1'+dp[5]\n if B[3]!=[] and dp[4]!='n':\n b='7'+dp[4]\n if B[4]!=[] and dp[3]!='n':\n c='47'\n if B[5]!=[] and dp[2]!='n':\n d=str(max(B[5]))+'1'\n if dp[7]=='n':\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(d)\n x=max(a,b,c,d)\n if x!=0:\n dp[7]=str(x)\n else:\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(d)\n e=int(dp[7])\n dp[7]=str(max(e,a,b,c,d))", 'N,M=map(int,input().split())\nA=list(map(int,input().split()))\nA.sort()\n\nif 1 in A:\n if N%2==0:\n print("1"*(N//2))\n else:\n if 7 in A:\n print("7"+"1"*(N//2-1))\n elif 5 in A:\n print("5"+"1"*(N//2-2))\n elif 3 in A:\n print("3"+"1"*(N//2-2))\n elif 2 in A:\n print("2"+"1"*(N//2-2))\n else:\n print("8"+"1"*(N//2-3))\nelif 7 in A:\n if N%3==0:\n print("7"*(N//3))\n elif N%3==1:\n if 4 in A:\n print("7"*(N//3-1)+"4")\n elif 8 in A:\n print("8"+"7"*(N//3-2))\n elif 5 in A:\n print("7"*(N//3-3)+"55")\n elif 3 in A:\n print("7"*(N//3-3)+"33")\n elif 2 in A:\n print("7"*(N//3-3)+"22")\n else:\n if 5 in A:\n print("7"*(N//3-1)+"5")\n elif 3 in A:\n print("7"*(N//3-1)+"3")\n elif 2 in A:\n print("7"*(N//3-1)+"2")\n elif 4 in A:\n print("7"*(N//3-2)+"44")\n elif 8 in A:\n print(print("7"*(N//3-4)+"88"))\n\nelse:\n B=[[] for i in range(0,10)]\n for i in range(0,M):\n if 2 in A:\n B[5].append(2)\n if 3 in A:\n B[5].append(3)\n if 4 in A:\n B[4].append(4)\n if 5 in A:\n B[5].append(5)\n if 6 in A:\n B[6].append(6)\n if 8 in A:\n B[7].append(8)\n if 9 in A:\n B[6].append(9)\n\n\n dp=[\'n\' for i in range(0,max(10,N+1))]\n for i in range(0,min(N+1,10)):\n if i==2:\n if 2 in A:\n dp[5]=\'2\'\n if i==3:\n if 3 in A:\n dp[5]=\'3\'\n if i==4:\n if 4 in A:\n dp[4]=\'4\'\n if i==5:\n if 5 in A:\n dp[5]=\'5\'\n if i==6:\n if 6 in A:\n dp[6]=\'6\'\n if i==8:\n if 8 in A:\n dp[7]=\'8\'\n if i==9:\n if 9 in A:\n dp[6]=\'9\'\n\n if N>=6:\n a=\'0\'\n b=\'0\'\n c=\'0\'\n if dp[6]==\'n\':\n a=int(a)\n b=int(b)\n c=int(c)\n x=max(a,b,c)\n if x!=0:\n dp[6]=str(x)\n else:\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(dp[6])\n dp[6]=str(max(a,b,c,d))\n\n if N>=7:\n a=\'0\'\n b=\'0\'\n c=\'0\'\n d=\'0\'\n if dp[7]==\'n\':\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(d)\n x=max(a,b,c,d)\n if x!=0:\n dp[7]=str(x)\n else:\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(d)\n e=int(dp[7])\n dp[7]=str(max(e,a,b,c,d))\n\n for i in range(8,N+1):\n a=\'0\'\n b=\'0\'\n c=\'0\'\n d=\'0\'\n e=\'0\'\n f=\'0\'\n if B[4] and dp[i-4]!=\'n\':\n c=\'4\'+dp[i-4]\n if B[5] and dp[i-5]!=\'n\':\n d=str(max(B[5]))+dp[i-5]\n if B[6] and dp[i-6]!=\'n\':\n e=str(max(B[6]))+dp[i-6]\n if B[7] and dp[i-7]!=\'n\':\n f=\'8\'+dp[i-7]\n a=int(a)\n b=int(b)\n c=int(c)\n d=int(d)\n e=int(e)\n f=int(f)\n x=max(a,b,c,d,e,f)\n if x==0:\n dp[i]=\'n\'\n else:\n dp[i]=str(x)\n print(int(dp[N]))\n'] | ['Wrong Answer', 'Accepted'] | ['s771943395', 's396460660'] | [3360.0, 16052.0] | [18.0, 921.0] | [2090, 3371] |
p03128 | u497046426 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["numbers = {'1': 2, '2': 5, '3': 5, '4': 4, '5': 5, '6': 6, '7': 3, '8': 7, '9': 6}\n\nN, M = map(int, input().split())\nA = list(input().split())\ncands = [(a, numbers[a]) for a in A]\n\ndp = {i: None for i in range(1, N+1)}\nfor c in cands:\n dp[c[1]] = int(c[0])\nfor i in range(2, N+1):\n for c in cands:\n j = i - c[1]\n if j >= 1 and dp[j] is not None:\n if dp[i] is None:\n dp[i] = int(''.join(str(dp[j]) + c[0]))\n else:\n if len(str(dp[i])) < len(str(dp[j]) + c[0]):\n dp[i] = int(str(dp[j]) + c[0])\n elif len(str(dp[i])) == len(str(dp[j]) + c[0]):\n dp[i] = max(dp[i], int(''.join(sorted(str(dp[j]) + c[0], reverse=True))))\nprint(''.join(sorted(dp[N], reverse=True)))", 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nnumbers = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp = {i: -1 for i in range(N+1)}\ndp[0] = 0\nfor i in range(N+1):\n for a in A:\n j = i + numbers[a]\n if j <= N:\n dp[j] = max(dp[j], dp[i]*10 + a)\nprint(dp[N])'] | ['Runtime Error', 'Accepted'] | ['s611952171', 's887443308'] | [8188.0, 15332.0] | [2104.0, 163.0] | [785, 297] |
p03128 | u505830998 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\nimport queue\n\n#+++++\n\ndef sa(v, p):\n\treturn v //p, v %p\n\ndef ggg(value, p_list, ctv):\n\tdd=p_list[:]\n\t#print(\'gfg\',dd)\n\tif len(dd)==0:\n\t\treturn None\n\ta=dd.pop(0)\n\tif a > value:\n\t\treturn None\n\t\n\tm,p=sa(value, a)\n\tif p == 0:\n\t\taa= [max(ctv[a])]*(m)\n\t\treturn aa\n\telse:\n\t\tbest_st=None\n\t\tfor i in range(min(m+1,20)):\n\t\t\tnokori=p+i*a\n\t\t\tret=bbb(nokori, ctv)\n\t\t\tif ret is not None:\n\t\t\t\taa= [max(ctv[a])]*(m-i)\n\t\t\t\tst=ret+aa\n\t\t\t\tif is_big(st, best_st):\n\t\t\t\t\tbest_st=st\n\t\t\t\t\n\t\treturn best_st\n\ndef bbb(value, ctv):\n\tol=queue.PriorityQueue()\n\tkk_costs=ctv.keys()\n\t\n\tbest_st=None\n\t\n\tcc=0\n\tst=[]\n\tol.put((cc,(cc, st)))\n\twhile not ol.empty():\n\t\tscc, (cc, st) = ol.get()\n\t\t#pa((scc,cc,st))\n\t\tif scc > value:\n\t\t\treturn best_st\n\t\t\t\n\t\tif scc == value:\n\t\t\tif is_big(st, best_st):\n\t\t\t\tbest_st=st\n\t\t\tcontinue\n\t\t\t\t\n\t\tfor cost in kk_costs:\n\t\t\ttst=st[:]\n\t\t\ttst.append(max(ctv[cost]))\n\t\t\tol.put((cc+cost, (cc+cost, tst)))\n\treturn None\n\t\ndef is_big(base, other):\n\tif other is None:\n\t\treturn True\n\tif base is None:\n\t\treturn False\n\t\t\n\tif len(base) != len(other):\n\t\treturn len(base) > len(other)\n\treturn base > other\n\n\ndef mk_value(a_ll):\n\tif a_ll is None:\n\t\treturn 0\n\t\t\n\ta_ll.sort(reverse=True)\n\ta_ll2=[str(v) for v in a_ll]\n\tans=\'\'.join(a_ll2)\n\treturn ans\n\t\ndef main():\n\tn , _ = map(int, input().split())\n\tal = list(map(int, input().split())\t)\n\t\n\tcost_list=[1000, 2,5,5,4,5,6,5,7,6]\n\t\n\taal=[(v, cost_list[v]) for v in al]\n\taal.sort(key=lambda x:-x[0])\n\tctv={}\n\tfor v in aal:\n\t\tctv.setdefault(v[1], []).append(v[0])\n\t\n\t#for kk in ctv.keys():\n\t#\tpa((kk,\':\',ctv[kk]))\n\taal=list(ctv.keys())\n\taal.sort()\n\t\n\tccc = ggg(n, aal, ctv)\n\tans=mk_value(ccc)\n\t\n\tprint(ans)\n\t\n\t\n#+++++\nisTest=False\n\ndef pa(v):\n\tif isTest:\n\t\tprint(v)\n\nif __name__ == "__main__":\n\tif sys.platform ==\'ios\':\n\t\tsys.stdin=open(\'inputFile.txt\')\n\t\tisTest=True\n\telse:\n\t\tpass\n\t\t#input = sys.stdin.readline\n\t\t\t\n\tret = main()\n\tif ret is not None:\n\t\tprint(ret)', 'import sys\nimport queue\n\n#+++++\n\ndef sa(v, p):\n\treturn v //p, v %p\n\ndef ggg(value, p_list, ctv):\n\tdd=p_list[:]\n\t#print(\'gfg\',dd)\n\tif len(dd)==0:\n\t\treturn None\n\ta=dd.pop(0)\n\tif a > value:\n\t\treturn None\n\t\n\tm,p=sa(value, a)\n\tif p == 0:\n\t\taa= [max(ctv[a])]*(m)\n\t\treturn aa\n\telse:\n\t\tbest_st=None\n\t\tfor i in range(min(m+1,6)):\n\t\t\tnokori=p+i*a\n\t\t\tret=bbb(nokori, ctv)\n\t\t\tif ret is not None:\n\t\t\t\taa= [max(ctv[a])]*(m-i)\n\t\t\t\tst=ret+aa\n\t\t\t\tif is_big(st, best_st):\n\t\t\t\t\tbest_st=st\n\t\t\t\t\n\t\treturn best_st\n\ndef bbb(value, ctv):\n\tol=queue.PriorityQueue()\n\tkk_costs=ctv.keys()\n\t\n\tbest_st=None\n\t\n\tcc=0\n\tst=[]\n\tol.put((cc,(cc, st)))\n\twhile not ol.empty():\n\t\tscc, (cc, st) = ol.get()\n\t\t#pa((scc,cc,st))\n\t\tif scc > value:\n\t\t\treturn best_st\n\t\t\t\n\t\tif scc == value:\n\t\t\tif is_big(st, best_st):\n\t\t\t\tbest_st=st\n\t\t\tcontinue\n\t\t\t\t\n\t\tfor cost in kk_costs:\n\t\t\ttst=st[:]\n\t\t\ttst.append(max(ctv[cost]))\n\t\t\tol.put((cc+cost, (cc+cost, tst)))\n\treturn None\n\t\ndef is_big(base, other):\n\tif other is None:\n\t\treturn True\n\tif base is None:\n\t\treturn False\n\t\t\n\tif len(base) != len(other):\n\t\treturn len(base) > len(other)\n\treturn base > other\n\n\ndef mk_value(a_ll):\n\tif a_ll is None:\n\t\treturn 0\n\t\t\n\ta_ll.sort(reverse=True)\n\ta_ll2=[str(v) for v in a_ll]\n\tans=\'\'.join(a_ll2)\n\treturn ans\n\t\ndef main():\n\tn , _ = map(int, input().split())\n\tal = list(map(int, input().split())\t)\n\t\n\tcost_list=[1000, 2,5,5,4,5,6,5,7,6]\n\t\n\taal=[(v, cost_list[v]) for v in al]\n\taal.sort(key=lambda x:-x[0])\n\tctv={}\n\tfor v in aal:\n\t\tctv.setdefault(v[1], []).append(v[0])\n\t\n\t#for kk in ctv.keys():\n\t#\tpa((kk,\':\',ctv[kk]))\n\taal=list(ctv.keys())\n\taal.sort()\n\t\n\tccc = ggg(n, aal, ctv)\n\tans=mk_value(ccc)\n\t\n\tprint(ans)\n\t\n\t\n#+++++\nisTest=False\n\ndef pa(v):\n\tif isTest:\n\t\tprint(v)\n\nif __name__ == "__main__":\n\tif sys.platform ==\'ios\':\n\t\tsys.stdin=open(\'inputFile.txt\')\n\t\tisTest=True\n\telse:\n\t\tpass\n\t\t#input = sys.stdin.readline\n\t\t\t\n\tret = main()\n\tif ret is not None:\n\t\tprint(ret)', 'import sys\nimport queue\n\n#+++++\n\ndef sa(v, p):\n\treturn v //p, v %p\n\ndef ggg(value, p_list, ctv):\n\tdd=p_list[:]\n\t#print(\'gfg\',dd)\n\tif len(dd)==0:\n\t\treturn None\n\ta=dd.pop(0)\n\tif a > value:\n\t\treturn None\n\t\n\tm,p=sa(value, a)\n\tif p == 0:\n\t\taa= [max(ctv[a])]*(m)\n\t\treturn aa\n\telse:\n\t\tbest_st=None\n\t\tfor i in range(min(m+1,6)):\n\t\t\tnokori=p+i*a\n\t\t\tret=bbb(nokori, ctv)\n\t\t\tif ret is not None:\n\t\t\t\taa= [max(ctv[a])]*(m-i)\n\t\t\t\tst=ret+aa\n\t\t\t\tif is_big(st, best_st):\n\t\t\t\t\tbest_st=st\n\t\t\t\t\n\t\treturn best_st\n\ndef bbb(value, ctv):\n\tol=queue.PriorityQueue()\n\tkk_costs=ctv.keys()\n\t\n\tbest_st=None\n\t\n\tcc=0\n\tst=[]\n\tol.put((cc,(cc, st)))\n\twhile not ol.empty():\n\t\tscc, (cc, st) = ol.get()\n\t\t#pa((scc,cc,st))\n\t\tif scc > value:\n\t\t\treturn best_st\n\t\t\t\n\t\tif scc == value:\n\t\t\tif is_big(st, best_st):\n\t\t\t\tbest_st=st\n\t\t\tcontinue\n\t\t\t\t\n\t\tfor cost in kk_costs:\n\t\t\ttst=st[:]\n\t\t\ttst.append(max(ctv[cost]))\n\t\t\tol.put((cc+cost, (cc+cost, tst)))\n\treturn None\n\t\ndef is_big(base, other):\n\tif other is None:\n\t\treturn True\n\tif base is None:\n\t\treturn False\n\t\t\n\tif len(base) != len(other):\n\t\treturn len(base) > len(other)\n\treturn base > other\n\n\ndef mk_value(a_ll):\n\tif a_ll is None:\n\t\treturn 0\n\t\t\n\ta_ll.sort(reverse=True)\n\ta_ll2=[str(v) for v in a_ll]\n\tans=\'\'.join(a_ll2)\n\treturn ans\n\t\ndef main():\n\tn , _ = map(int, input().split())\n\tal = list(map(int, input().split())\t)\n\t\n\tcost_list=[1000, 2,5,5,4,5,6,3,7,6]\n\t\n\taal=[(v, cost_list[v]) for v in al]\n\taal.sort(key=lambda x:-x[0])\n\tctv={}\n\tfor v in aal:\n\t\tctv.setdefault(v[1], []).append(v[0])\n\t\n\t#for kk in ctv.keys():\n\t#\tpa((kk,\':\',ctv[kk]))\n\taal=list(ctv.keys())\n\taal.sort()\n\t\n\tccc = ggg(n, aal, ctv)\n\tans=mk_value(ccc)\n\t\n\tprint(ans)\n\t\n\t\n#+++++\nisTest=False\n\ndef pa(v):\n\tif isTest:\n\t\tprint(v)\n\nif __name__ == "__main__":\n\tif sys.platform ==\'ios\':\n\t\tsys.stdin=open(\'inputFile.txt\')\n\t\tisTest=True\n\telse:\n\t\tpass\n\t\t#input = sys.stdin.readline\n\t\t\t\n\tret = main()\n\tif ret is not None:\n\t\tprint(ret)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s121419545', 's931342469', 's069028579'] | [49800.0, 4336.0, 4336.0] | [2106.0, 35.0, 35.0] | [1897, 1896, 1896] |
p03128 | u506858457 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m=map(int,input().split())\nx=[2,5,5,4,5,6,3,7,6]\na=[]\nfor i in map(int,input().split()):\n a.append([i,x[i-1]])\n \na.sort(reverse=True)\n\n\n\ndp=[0]*(n+1)\n\n\nfor i in range(m):\n\n for j in range(n+1):\n if j==0 or dp[j]!=0:\n \n if j+a[i][1]<=n:\n print(dp[j+a[i][1]],dp[j]*10+a[i][0])\n #print(max(dp[j+a[i][1]],dp[j]*10+a[i][0]))\n dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])\n\n\nprint(dp[n])', 'n,m=map(int,input().split())\nx=[2,5,5,4,5,6,3,7,6]\na=[]\nfor i in map(int,input().split()):\n a.append([i,x[i-1]])\n \na.sort(reverse=True)\ntuple(a)\n\n\ndp=[0]*(n+1)\n\n\nfor i in range(m):\n for j in range(n+1):\n if j==0 or dp[j]!=0:\n \n if j+a[i][1]<=n:\n print(dp[j+a[i][1]],dp[j]*10+a[i][0])\n #print(max(dp[j+a[i][1]],dp[j]*10+a[i][0]))\n dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])\n\n\nprint(dp[n])', 'n,m=map(int,input().split())\nx=[2,5,5,4,5,6,3,7,6]\na=[]\nfor i in map(int,input().split()):\n a.append([i,x[i-1]])\n \na.sort(reverse=True)\n\n\n\ndp=[0]*(n+1)\n\n\n\nfor i in range(m):\n\n #print(i)\n for j in range(n+1):\n #print(j,dp[j])\n if j==0 or dp[j]!=0:\n \n if j+a[i][1]<=n:\n print(dp[j+a[i][1]],dp[j]*10+a[i][0])\n #print(max(dp[j+a[i][1]],dp[j]*10+a[i][0]))\n dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])\n\n\nprint(dp[n])', 'n,m=map(int,input().split())\nx=[2,5,5,4,5,6,3,7,6]\na=[]\nfor i in map(int,input().split()):\n a.append([i,x[i-1]])\na.sort(reverse=True)\ndp=[0]*(n+1)\nfor i in range(m):\n for j in range(n+1):\n if j==0 or dp[j]!=0:\n if j+a[i][1]<=n:\n dp[j+a[i][1]]=max(dp[j+a[i][1]],dp[j]*10+a[i][0])\nprint(dp[n])\n'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s039796944', 's569956258', 's907076681', 's749042981'] | [74928.0, 75060.0, 75056.0, 16488.0] | [2105.0, 2105.0, 2105.0, 162.0] | [1363, 1216, 1481, 1131] |
p03128 | u511401499 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['ma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n\ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n\n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\td = dfs(num - ma_map[p])\n\t\t\tif d == -1: continue\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n\n\tmemo[num] = ret\n\treturn ret\n\nprint(ma_map[2])\nma.sort()\nprint(dfs(N))', 'ma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n\ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n\n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n\n\tmemo[num] = ret\n\treturn ret\n\nprint(ma_map[2])\nma.sort()\nprint(dfs(N))', 'import sys\nsys.setrecursionlimit(1000000)\n\nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n\ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n\n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\td = dfs(num - ma_map[p])\n\t\t\tif d == -1: continue\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n\n\tmemo[num] = ret\n\treturn ret\n\nprint(ma_map[2])\nma.sort()\nprint("{}".format(dfs(N)))', 'import sys\nsys.setrecursionlimit(1000000)\n\nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n\ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n\n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\td = dfs(num - ma_map[p])\n\t\t\tif d == -1: continue\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n\n\tmemo[num] = ret\n\treturn ret\n\nprint(ma_map[2])\nma.sort()\nprintln("{}".format(dfs(N)))', 'import sys\nsys.setrecursionlimit(1000000)\n\nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n\ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n\n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\td = dfs(num - ma_map[p])\n\t\t\tif d == -1: continue\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n\n\tmemo[num] = ret\n\treturn ret\n\nprint(ma_map[2])\nma.sort()\nprint(dfs(N))', 'import sys\nsys.setrecursionlimit(100000000000)\n \nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n \ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n \n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n \n\tmemo[num] = ret\n\treturn ret\n \nma.sort()\nprint(dfs(N))', 'import sys\nsys.setrecursionlimit(1000000)\n \nma_map = [ -1, 2, 5, 5, 4, 5, 6, 3, 7, 6 ]\nN, M = (int(i) for i in input().split())\nma = list(int(i) for i in input().split())\nmemo = [-1] * 100000\n \ndef dfs(num):\n\tif memo[num] != -1: return memo[num]\n\tif num == 0: return 0\n \n\tret = -1\n\tfor p in ma:\n\t\tif 0 <= num - ma_map[p]:\n\t\t\tret = max(dfs(num - ma_map[p]) * 10 + p, ret)\n \n\tmemo[num] = ret\n\treturn ret\n \nma.sort()\nprint(dfs(N))'] | ['Runtime Error', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s103408646', 's103882006', 's134941119', 's155111114', 's238522139', 's832294560', 's919807448'] | [5236.0, 5236.0, 17116.0, 3828.0, 17116.0, 3064.0, 17116.0] | [82.0, 77.0, 178.0, 19.0, 171.0, 18.0, 152.0] | [448, 396, 504, 506, 491, 432, 427] |
p03128 | u512007680 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['def num(k):\n if k == 1:\n return 1\n elif k == 7:\n return 3\n elif k == 4:\n return 4\n elif k == 2 or k == 3 or k == 5:\n return 5\n elif k == 6 or k == 9:\n return 6\n elif k == 8:\n return 7\n\nn, m = map(int,input().split())\nl = list(map(int,input().split()))\nl.sort(reverse = True)\n \ndp = [0] * (n+1)\n\nfor i in range(2,n+1):\n can = []\n for x in l:\n if i-num(x)>=0:\n can.append(dp[i-num(x)]+1)\n if can == []:\n dp[i] = 0\n else:\n dp[i] = max(can)\n \nprint(dp)\n\nanslist = [0] * dp[n]\n\nleft = n\n\nfor j in range(dp[n],0,-1):\n if j == 1:\n for x in l:\n if num(x) == left:\n anslist[j-1] = x\n break\n else:\n for x in l:\n if dp[left-num(x)] == j - 1:\n anslist[j-1] = x\n left = left-num(x)\n break\n \n print([j,x,left])\nprint(anslist)\n \n \nans = 0\n\nfor j in range(0,dp[n]):\n ans = ans + anslist[j] * (10 ** j)\n\nprint(ans)\n \n ', 'INF = 10 ** 6\n\ndef num(k):\n if k == 1:\n return 2\n elif k == 7:\n return 3\n elif k == 4:\n return 4\n elif k == 2 or k == 3 or k == 5:\n return 5\n elif k == 6 or k == 9:\n return 6\n elif k == 8:\n return 7\n\nn, m = map(int,input().split())\nl = list(map(int,input().split()))\nl.sort(reverse = True)\n \ndp = [(-1) * INF] * (n+1)\n\ndp[0] = 0\n\nfor i in range(2,n+1):\n can = []\n for x in l:\n if i-num(x)>=0:\n can.append(dp[i-num(x)]+1)\n if can == []:\n dp[i] = (-1) * INF\n else:\n dp[i] = max(can)\n \n#print(dp)\n\nanslist = [0] * dp[n]\n\nleft = n\n\nfor j in range(dp[n],0,-1):\n if j == 1:\n for x in l:\n if num(x) == left:\n anslist[j-1] = x\n break\n else:\n for x in l:\n if dp[left-num(x)] == j - 1:\n anslist[j-1] = x\n left = left-num(x)\n break\n \n #print([j,x,left])\n#print(anslist)\n \n \nans = 0\n\nfor j in range(0,dp[n]):\n ans = ans + anslist[j] * (10 ** j)\n\nprint(ans)\n \n '] | ['Wrong Answer', 'Accepted'] | ['s054418140', 's898323225'] | [4028.0, 3444.0] | [843.0, 224.0] | [1184, 1231] |
p03128 | u532966492 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N,M=map(int,input().split())\nA=list((map(int,input().split())))\n \nm=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nB=[]\n \nfor a in A:\n B.append(m[a-1])\n\nif [5,5] in B:\n if [2,5] in B:\n B.remove([2,5])\n if [3,5] in B: \n B.remove([3,5])\n\nif [3,5] in B and [2,5] in B:\n B.remove([2,5])\n\nif [7,3] in B:\n if [6,6] in B:\n B.remove([6,6])\n if [9,6] in B:\n B.remove([9,6])\n \nif [9,6] in B and [6,6] in B:\n B.remove([6,6])\n\nif [1,2] in B and [7,3] in B:\n if [2,5] in B:\n B.remove([2,5])\n if [3,5] in B:\n B.remove([3,5])\n if [5,5] in B:\n B.remove([5,5])\n if [8,7] in B:\n B.remove([8,7])\n\nif [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B:\n B.remove([8,7])\n \nif [4,4] in B and [7,3] and [8,7] in B:\n B.remove([8,7])\n \nif [1,2] in B and [4,4] in B:\n B.remove([4,4])\n\nmaxlist=[""]*(N+10)\n \nfor i in range(N+1):\n if i!=0 and maxlist[i]=="":\n continue\n else:\n for b in B:\n ans=maxlist[i]+str(b[0])\n _max=maxlist[i+b[1]]\n if i+b[1]>N:\n continue\n if len(ans)<len(_max):\n continue\n elif len(ans)>len(_max):\n maxlist[i+b[1]] = ans\n else:\n for j in range(len(ans)):\n if ans[j]>_max[j]:\n maxlist[i+b[1]] = ans\n \nprint(maxlist[N])', 'def concat(a,b):\n\treturn int(str(a)+str(b))\n\n\nN,M=map(int,input().split())\nA=list((map(int,input().split())))\n\nm=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nB=[]\n\nfor a in A:\n\tB.append(m[a-1])\n\nprint(B)\nmaxlist=[0]*(N+10)\n\nfor i in range(N+1):\n\tif i!=0 and maxlist[i]==0:\n\t\tcontinue\n\telse:\n\t\tfor b in B:\n\t\t\tif concat(maxlist[i],b[0]) > maxlist[i+b[1]]:\n\t\t\t\tmaxlist[i+b[1]] = concat(maxlist[i],b[0])\n\nprint(maxlist[N])', 'N,M=map(int,input().split())\nA=list((map(int,input().split())))\n \nm=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nB=[]\n \nfor a in A:\n B.append(m[a-1])\n \nmaxlist=[0]*(N+10)\n \nfor i in range(N+1):\n if i!=0 and maxlist[i]==0:\n continue\n else:\n for b in B:\n if int(str(maxlist[i])+str(b[0])) > maxlist[i+b[1]]:\n maxlist[i+b[1]] = concat(maxlist[i],b[0])\n \nprint(maxlist[N])', '%%timeit\n\ndef input():\n return next(input_sample)\n\n\ninput_sample=iter("""\n10000 9\n1 2 3 4 5 6 7 8 9\n""".split("\\n")[1:-1])\n\n\nN,M=map(int,input().split())\nA=list((map(int,input().split())))\n \nm=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nB=[]\n \nfor a in A:\n B.append(m[a-1])\n\nif [5,5] in B:\n if [2,5] in B:\n B.remove([2,5])\n if [3,5] in B: \n B.remove([3,5])\n\nif [3,5] in B and [2,5] in B:\n B.remove([2,5])\n\nif [7,3] in B:\n if [6,6] in B:\n B.remove([6,6])\n if [9,6] in B:\n B.remove([9,6])\n \nif [9,6] in B and [6,6] in B:\n B.remove([6,6])\n\nif [1,2] in B and [7,3] in B:\n if [2,5] in B:\n B.remove([2,5])\n if [3,5] in B:\n B.remove([3,5])\n if [5,5] in B:\n B.remove([5,5])\n if [8,7] in B:\n B.remove([8,7])\n\nif [1,2] in B and ([2,5] in B or [3,5] in B or [5,5] in B) and [8,7] in B:\n B.remove([8,7])\n \nif [4,4] in B and [7,3] and [8,7] in B:\n B.remove([8,7])\n \nif [1,2] in B and [4,4] in B:\n B.remove([4,4])\n\nmaxlist=[""]*(N+10)\n \nfor i in range(N+1):\n if i!=0 and maxlist[i]=="":\n continue\n else:\n for b in B:\n ans=maxlist[i]+str(b[0])\n _max=maxlist[i+b[1]]\n if i+b[1]>N:\n continue\n if len(ans)<len(_max):\n continue\n elif len(ans)>len(_max):\n maxlist[i+b[1]] = ans\n else:\n for j in range(len(ans)):\n if ans[j]>_max[j]:\n maxlist[i+b[1]] = ans\n \nprint(maxlist[N])', 'def comp(a,b):\n if sum(a)<sum(b):\n return "right"\n elif sum(a)>sum(b):\n return "left"\n else:\n for i in range(8,-1,-1):\n if a[i]<b[i]:\n return "right"\n elif a[i]>b[i]:\n return "left"\n else:\n return "equal"\n\nN,M=map(int,input().split())\nA=list((map(int,input().split())))\n \nm=[[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\nB=[]\n \nfor a in A:\n B.append(m[a-1])\n \nmaxlist=[[0]*9 for _ in range(N+1)]\n \nfor i in range(N+1):\n if i!=0 and sum(maxlist[i])==0:\n continue\n else:\n for b in B:\n if i+b[1]>N:\n continue\n ans=[maxlist[i][k] for k in range(9)]\n ans[b[0]-1]+=1\n _max=maxlist[i+b[1]]\n if comp(ans,_max) == "left":\n maxlist[i+b[1]]=[ans[k] for k in range(9)]\n \nfor i in range(8,-1,-1):\n print(str(i+1)*maxlist[N][i],end="")\nprint()'] | ['Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s236151593', 's512429186', 's679733185', 's920878504', 's687222556'] | [28912.0, 7900.0, 3064.0, 2940.0, 5252.0] | [2104.0, 2104.0, 18.0, 17.0, 394.0] | [1442, 429, 431, 1698, 955] |
p03128 | u543954314 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m = map(int,input().split())\ndp = [-10**5]*(n+1)\ndp[0] = 0\nt = [0,2,5,5,4,5,6,3,7,6]\na = set(map(int,input().split()))\nfor i in range(2,n+1):\n for x in a:\n if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:\n dp[i] = dp[i-t[x]] + 1\na = list(a)\na.sort(reverse=True)\ncur = ""\nidx = n\nwhile idx:\n for x in a:\n if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:\n cur += str(x)\n idx -= t[x]\n continue\nprint(cur)', 'n,m = map(int,input().split())\ndp = [-10**5]*(n+1)\ndp[0] = 0\nt = [0,2,5,5,4,5,6,3,7,6]\na = set(map(int,input().split()))\nfor i in range(2,n+1):\n for x in a:\n if i-t[x] >= 0 and dp[i] < dp[i-t[x]] + 1:\n dp[i] = dp[i-t[x]] + 1\na = list(a)\na.sort(reverse=True)\ncur = ""\nidx = n\nwhile idx:\n for x in a:\n if idx - t[x] >= 0 and dp[idx] == dp[idx-t[x]] + 1:\n cur += str(x)\n idx -= t[x]\n break\nprint(cur)'] | ['Wrong Answer', 'Accepted'] | ['s987383391', 's469875542'] | [3380.0, 3380.0] | [68.0, 68.0] | [428, 425] |
p03128 | u550943777 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["INF = 10**10\narr = [INF,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)\nans = ''\nwhile(N>0):\n for i in src[::-1]:\n if N - arr[i] > 0 and dp[N-arr[i]] == dp[N] - 1:\n ans += str(i)\n N -= arr[i]\n break\nprint(ans if ans else 0)", "INF = 10**10\narr = [10,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i+arr[j]] = max(dp[i+arr[j]],dp[i] + 1)\ndim = dp[N]\nans = '0'\n\nprint(ans)", "INF = 10**10\narr = [INF,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)\nans = ''\ndim = dp[N]\nfor _ in range(10**5):\n \n dim -= 1\n if dim <= 0:\n break\nprint(ans if ans else 0)", "INF = 10**10\narr = [INF,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)\nans = ''\ndim = dp[N]\nwhile(dim > 0):\n for i in src[::-1]:\n if dp[N-arr[i]] == dp[N] - 1:\n ans += str(i)\n N -= arr[i]\n dim -= 1\n break\nprint(0)", "INF = 10**10\narr = [INF,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)\nans = ''\ndim = dp[N]\n\nprint(ans if ans else 0)", "INF = 10**10\narr = [10,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())),key = lambda x:arr[x])\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N+1):\n for j in src:\n if i + arr[j] <= N:\n dp[i+arr[j]] = max(dp[i+arr[j]],dp[i] + 1)\ndim = dp[N]\nans = ''\nwhile(dim > 0):\n for i in src[::-1]:\n if dp[N-arr[i]] + 1 == dp[N]:\n ans += str(i)\n N -= arr[i]\n dim -= 1\n break\nprint(ans)", "INF = 10**10\narr = [INF,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)\nans = ''\ndim = dp[N]\n\nprint(ans if ans else 0)", "INF = 10**10\narr = [INF,2,5,5,4,5,6,3,7,6]\nN,M = map(int,input().split())\nsrc = sorted(list(map(int,input().split())))\n\ndp = [-INF]*(N+1)\ndp[0] = 0\nfor i in range(N):\n for j in src:\n if i + arr[j] <= N:\n dp[i + arr[j]] = max(dp[i + arr[j]], dp[i] + 1)\nans = ''\nwhile(N>0):\n for i in src[::-1]:\n if N - arr[i] >= 0 and dp[N-arr[i]] == dp[N] - 1:\n ans += str(i)\n N -= arr[i]\n break\nprint(ans if ans else 0)"] | ['Time Limit Exceeded', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s004143335', 's155273223', 's210589822', 's441546976', 's489136105', 's793533108', 's920770855', 's566654482'] | [3424.0, 3312.0, 3308.0, 3312.0, 3312.0, 3312.0, 3312.0, 3312.0] | [2104.0, 80.0, 80.0, 99.0, 75.0, 98.0, 75.0, 93.0] | [467, 473, 521, 469, 483, 490, 483, 468] |
p03128 | u556225812 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\ndp = [-1] * (N+1)\nneed = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp[0] = 0\n\nfor i in range(N+1):\n for j in A:\n if i + need[j] > N:\n continue\n dp[i+need[j]] = max(dp[i+need[j]], dp[i]*10+j])\nprint(dp[N])', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\ndp = [-1] * (N+1)\nneed = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\ndp[0] = 0\n\nfor i in range(N+1):\n for j in A:\n if i + need[j] > N:\n continue\n dp[i+need[j]] = max(dp[i+need[j]], dp[i]*10+j)\nprint(dp[N])'] | ['Runtime Error', 'Accepted'] | ['s098208871', 's897553039'] | [2940.0, 14692.0] | [17.0, 165.0] | [291, 290] |
p03128 | u561339958 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = [int(a) for a in input().split()]\nL = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA.sort(reverse = True)\nprint(A)\ndp = [0] + ([-1]*N)\nprint(dp)\nfor i in range(1, N+1):\n for a in A:\n if L[a] <= i:\n dp[i] = max(dp[i], dp[i-L[a]] * 10 + a)\nprint(dp)\nprint(dp[-1])', 'N, M = map(int, input().split())\nA = [int(a) for a in input().split()]\nL = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA.sort(reverse = True)\n#print(A)\ndp = [0] + ([-1]*N)\n#print(dp)\nfor i in range(1, N+1):\n for a in A:\n if L[a] <= i:\n dp[i] = max(dp[i], dp[i-L[a]] * 10 + a)\n#print(dp)\nprint(dp[-1])\n'] | ['Wrong Answer', 'Accepted'] | ['s976299158', 's360906923'] | [88160.0, 14692.0] | [1518.0, 148.0] | [305, 309] |
p03128 | u565035185 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['#encoding: utf-8\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nmatch = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nA.sort()\nA.reverse()\n\ndp = [-1] * (N + 1)\ndp[0] = 0\n\nfor i in range(N + 1):\n for a in A:\n if i - match[a] >= 0:\n dp[i] = max(dp[i - match[a]] * 10 + a, dp[i])\n print(dp)\n\nprint(dp[N])\n', '#encoding: utf-8\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nmatch = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nA.sort()\nA.reverse()\n\ndp = [-1] * (N + 1)\ndp[0] = 0\n\nfor i in range(N + 1):\n for a in A:\n if i - match[a] >= 0:\n dp[i] = max(dp[i - match[a]] * 10 + a, dp[i])\n\nprint(dp[N])\n'] | ['Runtime Error', 'Accepted'] | ['s305875117', 's950546719'] | [135184.0, 14692.0] | [1550.0, 151.0] | [335, 321] |
p03128 | u580093517 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N,M = map(int,input().split())\nA = list(map(int,input().split()))\nweight = [2,5,5,4,5,6,3,7,6]\ndp=[-1]*(N+1)\ndp[0] = 0\nfor i in range(N+1):\n if dp[i] == -1:continue\n for a in A:\n if i+weight[a]<N+1:\n dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)\nprint(dp[-1])', '\nN,M=map(int,input().split())\nA=list(map(int,input().split()))\nweight=[0,2,5,5,4,5,6,3,7,6]\ndp=[-1]*(N+1)\ndp[0]=0\n\nfor i in range((N+1)//2):\n for a in A:\n if i+weight[a]<N+1:\n dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)\n \nprint(dp[N])', '\nN,M=map(int,input().split())\nA=list(map(int,input().split()))\nweight=[0,2,5,5,4,5,6,3,7,6]\ndp=[-1]*(N+1)\ndp[0]=0\n\nfor i in range(N+1):\n if dp[i] == -1:continue\n for a in A:\n if i+weight[a]<N+1:\n dp[i+weight[a]]=max(dp[i+weight[a]],dp[i]*10+a)\n \n \u3000 \nprint(dp[N])', 'N,M = map(int,input().split())\nA = list(map(int,input().split()))\nweight = [0,2,5,5,4,5,6,3,7,6]\ndp=[-1]*(N+1)\ndp[0] = 0\nfor i in range(N+1):\n if dp[i] == -1:continue\n for a in A:\n if i+weight[a]<N+1:\n dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)\nprint(dp[-1])'] | ['Runtime Error', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s574240213', 's873254294', 's969336050', 's781452865'] | [7900.0, 6116.0, 3064.0, 14692.0] | [68.0, 75.0, 17.0, 182.0] | [287, 932, 1175, 289] |
p03128 | u580327099 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport sys\n\ninput = sys.stdin.readline\n\nMATCH_NUM = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndef main():\n N, M = map(int, input().split())\n A = list(map(int, input().split()))\n A.sort(reverse=True)\n\n \n dp = [-1 for _ in range(N+1)]\n dp[0] = 0\n dp[1] = 0\n for i in range(N+1):\n for a in A:\n if i < MATCH_NUM[a]:\n continue\n dp[i] = max(dp[i], dp[i-MATCH_NUM[a]] + 1)\n\n max_digit_num = dp[N]\n\n res = ''\n for _ in range(max_digit_num):\n m = -1\n for a in A:\n if N < MATCH_NUM[a]:\n continue\n if dp[N-MATCH_NUM[a]] == dp[N]-1:\n if a > m:\n m = a\n res += str(m)\n N -= MATCH_NUM[m]\n print(res)\nmain()\n", "#!/usr/bin/env python3\n# -*- coding: utf-8 -*-\n\nimport sys\n\ninput = sys.stdin.readline\n\nMATCH_NUM = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndef main():\n N, M = map(int, input().split())\n A = list(map(int, input().split()))\n\n \n dp = [-1 for _ in range(N+1)]\n dp[0] = 0\n for i in range(N+1):\n for a in A:\n if i < MATCH_NUM[a]:\n continue\n dp[i] = max(dp[i], dp[i-MATCH_NUM[a]] + 1)\n\n max_digit_num = dp[N]\n\n res = ''\n for _ in range(max_digit_num):\n m = -1\n for a in A:\n if N < MATCH_NUM[a]:\n continue\n if dp[N-MATCH_NUM[a]] == dp[N]-1:\n if a > m:\n m = a\n res += str(m)\n N -= MATCH_NUM[m]\n print(res)\nmain()\n"] | ['Wrong Answer', 'Accepted'] | ['s324591993', 's150691728'] | [3312.0, 3380.0] | [65.0, 59.0] | [838, 799] |
p03128 | u600402037 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = set(map(int, input().split()))\n\ndp = [-1] * (N+1)\nweights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndp[0] = 0\n\nfor i in range(N+1):\n for a in A:\n if i + weights[a] > N:\n continue\n dp[i + weights[a]] = max(dp[i + weights[a]], dp[i] * 10 + weights[a])\nprint(dp[N])\n\n\n', "# coding: utf-8\nimport sys\n\nsr = lambda: sys.stdin.readline().rstrip()\nir = lambda: int(sr())\nlr = lambda: list(map(int, sr().split()))\n\n\nN, M = lr()\nA = lr()\nmatches = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA = [(matches[a], a) for a in A]\nA.sort(key = lambda x: x[1], reverse=True)\nA.sort(key = lambda x: x[0])\ntop_match = A[0][0]\ndp = [None] * (N+1)\ndp[0] = []\nused = set()\nfor match, num in A:\n if match in used:\n continue\n used.add(match)\n for x in range(N+1):\n if x - match < 0:\n continue\n if dp[x] == None and dp[x-match] != None:\n dp[x] = dp[x-match] + [num]\n elif dp[x] != None and dp[x-match] != None:\n if len(dp[x-match]) >= len(dp[x]):\n dp[x] = dp[x-match] + [num]\n elif len(dp[x-match]) == len(dp[x]) - 1 and num > dp[x][-1]:\n dp[x] = dp[x-match] + [num]\n\nX = dp[N]\nX.sort(reverse=True)\nanswer = ''.join(list(map(str, X)))\nprint(answer)\n# 37\n", 'N, M = map(int, input().split())\nA = set(map(int, input().split()))\n\ndp = [-1] * (N+1)\nweights = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndp[0] = 0\n\nfor i in range(N+1):\n for a in A:\n if i + weights[a] > N:\n continue\n dp[i + weights[a]] = max(dp[i + weights[a]], dp[i] * 10 + a)\nprint(dp[N])\n\n'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s835458324', 's903138063', 's697275329'] | [14700.0, 199412.0, 14692.0] | [175.0, 736.0, 172.0] | [373, 1023, 363] |
p03128 | u631277801 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\nstdin = sys.stdin\n\nsys.setrecursionlimit(10 ** 7)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x) - 1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nnum_cost = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nchosen = {}\n\nn, m = li()\na = list(li())\n\nfor ai in a:\n chosen[str(ai)] = num_cost[ai]\n\ndp = ["ng"]*(n+1)\ndp[0] = ""\nfor i in range(n):\n if dp[i] == "ng":\n continue\n\n for num, cost in chosen.items():\n if i + cost <= n and dp[i+cost] == "ng":\n dp[i+cost] = "".join(sorted(num+dp[i]))\n\n elif i + cost <= n:\n if len(dp[i+cost]) < len(dp[i]) + 1:\n dp[i+cost] = "".join(sorted(num+dp[i]))\n\n elif len(dp[i+cost]) > len(dp[i]) + 1:\n dp[i+cost] = dp[i+cost]\n\n else:\n dp[i+cost] = max(dp[i+cost],\n "".join(sorted(num+dp[i])))\n\nprint(dp[n])', 'import sys\nstdin = sys.stdin\n \nsys.setrecursionlimit(10**5) \n \ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x)-1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\ndic = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nn,m = li()\na = list(li())\n\nuse = {}\nfor ai in a:\n if dic[ai] not in use.keys():\n use.update({dic[ai]: ai})\n else:\n dic[ai] = max(dic[ai], ai)\n \n\ndesc = {}\nedge = {}\nfor idx, num in enumerate(sorted(use.values(), reverse=True)):\n desc.update({idx: num})\n edge.update({idx: dic[num]})\n \n \n\nINF = float(\'inf\')\ndp = [[-INF]*len(use) for _ in range(n+1)]\ndp[0] = [0]*len(use)\nfor i in range(1, n+1):\n for idx in range(len(use)):\n modefied = False\n if i - edge[idx] < 0:\n continue\n \n if sum(dp[i]) < sum(dp[i-edge[idx]])+1:\n dp[i] = dp[i-edge[idx]].copy()\n dp[i][idx] += 1\n \n modefied = True\n\n elif sum(dp[i]) == sum(dp[i-edge[idx]])+1:\n tmp = dp[i-edge[idx]].copy()\n tmp[idx] += 1\n \n for orgi, tmpi in zip(dp[i], tmp):\n if orgi == tmpi:\n continue\n \n elif orgi > tmpi:\n break\n \n else:\n dp[i] = tmp.copy()\n modefied = True\n break\n \n if modefied:\n break\n\nans = ""\nfor num, cnt in zip(desc.values(), dp[-1]):\n ans = ans + str(num)*cnt\n \nprint(ans)', 'import sys\nstdin = sys.stdin\n\nsys.setrecursionlimit(10 ** 7)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x) - 1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nnum_cost = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 6,\n 9: 5}\n\nchosen = {}\n\nn, m = li()\na = list(li())\n\nfor ai in a:\n chosen[str(ai)] = num_cost[ai]\n\ndp = ["ng"]*(n+1)\ndp[0] = ""\nfor i in range(n):\n if dp[i] == "ng":\n continue\n\n for num, cost in chosen.items():\n if i + cost <= n and dp[i+cost] == "ng":\n dp[i+cost] = num + dp[i]\n\n elif i + cost <= n:\n if len(dp[i+cost]) < len(dp[i]) + 1:\n dp[i+cost] = num + dp[i]\n\n elif len(dp[i+cost]) > len(dp[i]) + 1:\n dp[i+cost] = dp[i+cost]\n\n else:\n dp[i+cost] = max(dp[i+cost],\n "".join(sorted(num+dp[i])))\n\nprint(dp[n])', 'import sys\nstdin = sys.stdin\n\nsys.setrecursionlimit(10 ** 7)\n\ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x) - 1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\nnum_cost = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 6,\n 9: 5}\n\nchosen = {}\n\nn, m = li()\na = list(li())\n\nfor ai in a:\n chosen[str(ai)] = num_cost[ai]\n\ndp = ["ng"]*(n+1)\ndp[0] = ""\nfor i in range(n):\n if dp[i] == "ng":\n continue\n\n for num, cost in chosen.items():\n if i + cost <= n and dp[i+cost] == "ng":\n dp[i+cost] = num + dp[i]\n\n elif i + cost <= n:\n dp[i+cost] = str(max(int(dp[i+cost]), int(num + dp[i])))\n\nprint(dp[n]', 'import sys\nstdin = sys.stdin\n \nsys.setrecursionlimit(10**5) \n \ndef li(): return map(int, stdin.readline().split())\ndef li_(): return map(lambda x: int(x)-1, stdin.readline().split())\ndef lf(): return map(float, stdin.readline().split())\ndef ls(): return stdin.readline().split()\ndef ns(): return stdin.readline().rstrip()\ndef lc(): return list(ns())\ndef ni(): return int(stdin.readline())\ndef nf(): return float(stdin.readline())\n\ndic = {1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6}\n\nn,m = li()\na = list(li())\n\nuse = {}\nfor ai in a:\n if dic[ai] not in use.keys():\n use.update({dic[ai]: ai})\n else:\n use[dic[ai]] = max(use[dic[ai]], ai)\n \n\ndesc = {}\nedge = {}\nfor idx, num in enumerate(sorted(use.values(), reverse=True)):\n desc.update({idx: num})\n edge.update({idx: dic[num]})\n \n \n\nINF = float(\'inf\')\ndp = [[-INF]*len(use) for _ in range(n+1)]\ndp[0] = [0]*len(use)\nfor i in range(1, n+1):\n cand = dp[i].copy()\n for idx in range(len(use)):\n if i - edge[idx] < 0:\n continue\n\n if sum(cand) < sum(dp[i-edge[idx]])+1:\n tmp = dp[i-edge[idx]].copy()\n tmp[idx] += 1\n cand = tmp.copy()\n \n\n elif sum(cand) == sum(dp[i-edge[idx]])+1:\n tmp = dp[i-edge[idx]].copy()\n tmp[idx] += 1\n \n for orgi, tmpi in zip(cand, tmp):\n if orgi == tmpi:\n continue\n \n elif orgi > tmpi:\n break\n \n else:\n cand = tmp.copy()\n break\n \n dp[i] = cand\n \n\nans = ""\nfor num, cnt in zip(desc.values(), dp[-1]):\n ans = ans + str(num)*cnt\n \nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Wrong Answer', 'Runtime Error', 'Accepted'] | ['s116600748', 's164673513', 's258965654', 's549462875', 's653824573'] | [28008.0, 4596.0, 30196.0, 3064.0, 4596.0] | [2105.0, 43.0, 2104.0, 17.0, 122.0] | [1275, 1895, 1245, 1006, 1849] |
p03128 | u652057333 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["# D\nn, m = map(int, input().split())\na = list(map(int, input().split()))\nmatch_list = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\n\nuse_list = []\n\n# if i[0] in a:\n# use_list.append(i)\nuse_list = match_list\nuse_list.sort(key=lambda x:x[1])\nprint(use_list)\nans_list = []\nnum = n // use_list[0][1]\nwhile n > 0:\n if n % use_list[0][1] == n:\n n += use_list[0][1]\n ans_list.pop(0)\n \n for i in use_list:\n break\n elif n >= use_list[0][1]:\n n -= use_list[0][1]\n ans_list.append(str(use_list[0][0]))\n\nans_list.sort()\nans_list.reverse()\nprint(''.join(map(str, ans_list)))", "# D\nn, m = map(int, input().split())\na = list(map(int, input().split()))\nmatch_list = [[1,2],[2,5],[3,5],[4,4],[5,5],[6,6],[7,3],[8,7],[9,6]]\n\nuse_list = []\n\n# if i[0] in a:\n# use_list.append(i)\nuse_list = match_list\nuse_list.sort(key=lambda x:x[1])\nprint(use_list)\nans_list = []\nnum = n // use_list[0][1]\nwhile n > 0:\n if n % use_list[0][1] == n:\n n += use_list[0][1]\n ans_list.pop(0)\n \n for i in use_list:\n break\n elif n >= use_list[0][1]:\n n -= use_list[0][1]\n ans_list.append(str(use_list[0][0]))\n\nans_list.sort()\nans_list.reverse()\nprint(''.join(map(str, ans_list)))", '# D\nn,m = map(int, input().split())\nb = [0,2,5,5,4,5,6,3,7,6]\na = [0]+list(map(int, input().split()))\nf = [-1]*10010\nf[0]=0\nfor i in range(1,n+1):\n for j in range(1,m+1):\n x = a[j]\n if(i-b[x]<0):\n continue\n f[i] = max(f[i],f[i-b[x]]*10 + x)\nprint(f[n])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s791633739', 's799606260', 's738835357'] | [3064.0, 3064.0, 14516.0] | [18.0, 17.0, 162.0] | [660, 660, 287] |
p03128 | u667084803 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["N, M = map(int, input().split())\nA = list(map(int, input().split()))\nhonsuu = [0,2,5,5,4,5,6,3,7,6]\naval = []\nfor a in A:\n aval += [honsuu[a]]\naval.sort()\n\ndp = [0] \n\nfor i in range(1,N+1):\n for b in aval:\n if i < b:\n continue\n else:\n dp += [dp[i-b] + 1]\n break\n else:\n dp += [-1]\n\n\n\nA.sort(reverse=True)\nans = []\nfor i in range(dp[N],1,-1):\n for a in A:\n if N - honsuu[a] < 0:continue\n if dp[N - honsuu[a]] == dp[N] - 1:\n N -= honsuu[a]\n ans += [a]\n break\n \nfinal = 0\nfor i in range(10):\n if i in A and honsuu[i] == N:\n final = i\nans += [final]\nprint(''.join(map(str, ans)))", 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\nhonsuu = [0,2,5,5,4,5,6,3,7,6]\naval = []\nfor a in A:\n aval += [honsuu[a]]\naval.sort()\n\ndp = [0]+ [-float("INF")]*N \n\nfor i in range(1,N+1):\n for b in aval:\n if i < b:\n continue\n else:\n dp[i] = dp[i-b] + 1\n break\n \n\n\nA.sort(reverse=True)\nans = []\nfor i in range(dp[N],1,-1):\n for a in A:\n if N - honsuu[a] < 0:continue\n if dp[N - honsuu[a]] == dp[N] - 1:\n N -= honsuu[a]\n ans += [a]\n break\n \nfinal = 0\nfor i in range(10):\n if i in A and honsuu[i] == N:\n final = i\nans += [final]\nprint(\'\'.join(map(str, ans)))', 'N, M = map(int, input().split())\nA = list(map(int, input().split()))\nhonsuu = [0,2,5,5,4,5,6,3,7,6]\naval = []\nfor a in A:\n aval += [honsuu[a]]\naval.sort()\n\ndp = [0]+ [-float("INF")]*N \n\nfor i in range(1,N+1):\n for b in aval:\n if i < b:\n continue\n elif dp[i-b] >= 0:\n dp[i] = dp[i-b] + 1\n break\n \n\n\nA.sort(reverse=True)\nans = []\nfor i in range(dp[N],0,-1):\n for a in A:\n if N - honsuu[a] < 0:continue\n if dp[N - honsuu[a]] == dp[N] - 1:\n N -= honsuu[a]\n ans += [a]\n break\nprint(\'\'.join(map(str, ans)))'] | ['Wrong Answer', 'Runtime Error', 'Accepted'] | ['s184868623', 's500399730', 's010798688'] | [3700.0, 3692.0, 3700.0] | [39.0, 41.0, 41.0] | [810, 812, 728] |
p03128 | u684120680 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import math\n\nn,m = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\n\nset = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[6,6],[8,7]]\n\nif 3 in a:\n if 5 in a:\n a.remove(3)\n m -= 1\n a.remove(2)\n m -= 1\n\nif 9 in a:\n a.remove(6)\n m -= 1\n \nexist = [i for i in set if i[0] in a]\n\nnum = 0\nketa = 0\nfor i in exist:\n if i[0] > num and n//i[1] >= keta:\n num = i[0]\n honsu = i[1]\n keta = n//honsu\n amari = n%honsu\n break\n\nfor l in range(keta-1):\n exist_tmp = [i for i in exist if i[0] != num]\n bit = math.ceil(math.log2(m-1))\n for i in range(1,keta+1):\n kouho = []\n for j in range((2**bit)**i):\n nokori = amari + honsu * i\n change = []\n for k in range(i):\n tmp = (j >> k*bit) & (2**bit-1)\n if tmp >= m-1:\n continue\n nokori -= exist_tmp[tmp][1]\n change.append(exist_tmp[tmp][0])\n if nokori < 0:\n break\n if nokori == 0:\n kouho.append(change)\n if len(kouho) != 0:\n break\n if len(kouho) != 0:\n break\n else:\n keta -= 1\n num = 0\n for i in exist:\n if i[0] > num and n//i[1] >= keta:\n num = i[0]\n honsu = i[1]\n amari = n%honsu\n break\n\nkouho = [sorted(i,reverse=True) for i in kouho]\nkouho_tmp = []\nfor i in kouho:\n if i not in kouho_tmp:\n kouho_tmp.append(i)\nkouho = kouho_tmp\nkouho.sort(reverse=True)\n\nif len(kouho) > 1:\n for i in range(len(kouho[0])):\n max_num = 0\n for j in range(len(kouho)):\n if kouho[j][i] > max_num:\n max_num = kouho[j][i]\n kouho = [k for k in kouho if k[i] == max_num]\n if len(kouho) == 1:\n break\n \nans = [num]*(keta-len(kouho[0])) + kouho[0]\nans.sort(reverse=True)\n\nans_txt = ''\nfor i in ans:\n ans_txt += str(i)\nprint(ans_txt)", "import math\n\nn,m = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\n\n\nset = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[6,6],[8,7]]\n\n\nif 2 in a:\n if 3 in a or 5 in a:\n a.remove(2)\n m -= 1\n\nif 3 in a:\n if 5 in a:\n a.remove(3)\n m -= 1\n \nif 6 in a:\n if 9 in a:\n a.remove(6)\n m -= 1\n\n\nmax_a = max(a)\n\n\nexist_set = [i for i in set if i[0] in a]\n\nans_kouho = []\n\nketa = 0\nnum = 0\nfor i in exist_set:\n keta_tmp = n//i[1]\n num_tmp = i[0]\n amari_tmp = n % i[1]\n \n if amari_tmp != 0 and num_tmp == max_a:\n continue\n if keta_tmp >= keta and num_tmp > num:\n keta = keta_tmp\n num = num_tmp\n amari = amari_tmp\n honsu = i[1]\n\n \n if amari == 0:\n ans_kouho.append(int(str(num)*keta))\n continue\n \n \n\n \n exist_yet = [i for i in exist_set if i[0] != num]\n m -= 1\n\n \n for i in range(1,honsu):\n\n \n bit = math.ceil(math.log2(m))\n kouho = []\n for j in range((2**m)*i):\n change = []\n nokori = amari + honsu * i\n for k in range(i):\n bit_index = (j >> k*bit) & (2**m-1)\n\n \n if bit_index >= m:\n break\n\n \n change.append(exist_yet[bit_index][0])\n nokori -= exist_yet[bit_index][1]\n\n if nokori < 0:\n break\n\n \n if nokori == 0:\n kouho.append(change)\n \n \n if len(kouho) != 0:\n break\n\n if len(kouho) == 0:\n continue\n \n \n\n \n kouho = [sorted(i,reverse=True) for i in kouho]\n\n \n kouho_tmp = []\n for i in kouho:\n if i not in kouho_tmp:\n kouho_tmp.append(i)\n kouho = kouho_tmp\n\n \n for i in range(len(kouho[0])):\n if len(kouho) == 1:\n break\n max_i = max([j[i] for j in kouho])\n kouho = [j for j in kouho if j[i] == max_i]\n kouho = kouho[0]\n\n ans = [num]*(keta-len(kouho)) + kouho\n ans.sort(reverse=True)\n ans_str = ''\n for i in ans:\n ans_str += str(i)\n ans_kouho.append(int(ans_str))\n\nans_kouho.sort()\nprint(ans_kouho)\nprint(ans_kouho[-1])", "import math\n\nn,m = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\n\nset = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[6,6],[8,7]]\n\nif 3 in a:\n if 5 in a:\n a.remove(3)\n a.remove(2)\n\nif 9 in a:\n a.remove(6)\n \nexist = [i for i in set if i[0] in a]\n\nnum = 0\nketa = 0\nfor i in exist:\n if i[0] > num and n//i[1] >= keta:\n num = i[0]\n honsu = i[1]\n keta = n//honsu\n amari = n%honsu\n break\n\nfor l in range(keta-1):\n bit = math.ceil(math.log2(m-1))\n exist_tmp = [i for i in exist if i[0] != num]\n for i in range(1,keta+1):\n kouho = []\n for j in range((2**bit)**i):\n nokori = amari + honsu * i\n change = []\n for k in range(i):\n tmp = (j >> k*bit) & (2**bit-1)\n if tmp >= m:\n continue\n nokori -= exist_tmp[tmp][1]\n change.append(exist_tmp[tmp][0])\n if nokori < 0:\n break\n if nokori == 0:\n kouho.append(change)\n if len(kouho) != 0:\n break\n if len(kouho) != 0:\n break\n else:\n keta -= 1\n num = 0\n for i in exist:\n if i[0] > num and n//i[1] >= keta:\n num = i[0]\n honsu = i[1]\n amari = n%honsu\n break\n\nkouho = [sorted(i,reverse=True) for i in kouho]\nkouho_tmp = []\nfor i in kouho:\n if i not in kouho_tmp:\n kouho_tmp.append(i)\nkouho = kouho_tmp\nkouho.sort(reverse=True)\n\nif len(kouho) > 1:\n for i in range(len(kouho[0])):\n max_num = 0\n for j in range(len(kouho)):\n if kouho[j][i] > max_num:\n max_num = kouho[j][i]\n kouho = [k for k in kouho if k[i] == max_num]\n if len(kouho) == 1:\n break\n \nans = [num]*(keta-len(kouho[0])) + kouho[0]\nans.sort(reverse=True)\n\nans_txt = ''\nfor i in ans:\n ans_txt += str(i)\nprint(ans_txt)", "import math\n\nn,m = [int(i) for i in input().split()]\na = [int(i) for i in input().split()]\n\n\nset = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[6,6],[8,7]]\n\n\nif 2 in a:\n if 3 in a or 5 in a:\n a.remove(2)\n m -= 1\n\nif 3 in a:\n if 5 in a:\n a.remove(3)\n m -= 1\n \nif 6 in a:\n if 9 in a:\n a.remove(6)\n m -= 1\n\n\nexist_set = [i for i in set if i[0] in a]\n\n\nmax_honsu = max([i[1] for i in exist_set])\n\n\nm -= 1\n\n\nmax_keta = 0\nans_kouho = []\n\nfor exist_one in exist_set:\n keta_tmp = n//exist_one[1]\n num_tmp = exist_one[0]\n amari_tmp = n % exist_one[1]\n honsu_tmp = exist_one[1]\n \n ###print(keta_tmp,num_tmp)\n \n \n if amari_tmp != 0 and honsu_tmp == max_honsu:\n continue\n if keta_tmp >= max_keta:\n keta = keta_tmp\n num = num_tmp\n amari = amari_tmp\n honsu = honsu_tmp\n\n \n if amari == 0:\n ans_kouho.append(int(str(num)*keta))\n max_keta = keta\n continue\n \n \n\n \n exist_yet = [inc for inc in exist_set if inc[0] != num]\n\n \n for keta_num in range(1,min(max_honsu,keta+1)):\n \n kouho = []\n\n \n \n bit = math.ceil(math.log2(m+1))\n for all_bit in range((2**m)*keta_num):\n change = []\n nokori = amari + honsu * keta_num\n for bit_conf in range(keta_num):\n bit_index = (all_bit >> bit_conf*bit) & (2**m-1)\n\n \n if bit_index > m:\n break\n \n \n if bit_index == m:\n change.append(0)\n continue\n\n \n change.append(exist_yet[bit_index][0])\n nokori -= exist_yet[bit_index][1]\n\n if nokori < 0:\n break\n \n if bit_index > m or nokori < 0:\n continue\n\n \n if nokori == 0:\n kouho.append(change)\n \n \n if len(kouho) != 0:\n\n \n del_len = len(kouho[0])\n\n \n kouho = [[inc_1 for inc_1 in inc_2 if inc_1 != 0] for inc_2 in kouho]\n\n \n max_len = max([len(inc) for inc in kouho])\n kouho = [inc for inc in kouho if len(inc) == max_len]\n \n max_keta = keta - del_len + max_len\n\n \n kouho = [sorted(kouho_one,reverse=True) for kouho_one in kouho]\n\n \n kouho_tmp = []\n for kouho_one in kouho:\n if kouho_one not in kouho_tmp:\n kouho_tmp.append(kouho_one)\n kouho = kouho_tmp\n\n \n if len(kouho) != 1:\n for kouho_one in range(len(kouho[0])):\n max_i = max([inc[kouho_one] for inc in kouho])\n kouho = [inc for inc in kouho if inc[kouho_one] == max_i]\n kouho = kouho[0]\n\n ans = [num]*(keta-del_len) + kouho\n ans.sort(reverse=True)\n ans_str = ''\n for ans_one in ans:\n ans_str += str(ans_one)\n ans_kouho.append(int(ans_str))\n\nans_kouho.sort()\n\nprint(ans_kouho[-1])\n"] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s561974241', 's602130711', 's855480214', 's077788232'] | [3308.0, 3280.0, 3192.0, 3316.0] | [2104.0, 21.0, 2104.0, 22.0] | [1764, 3027, 1733, 4017] |
p03128 | u686036872 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\n\nA = list(map(int, input().split()))\nB = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nDP = [-1]*(N+1)\nDP[0] = 0 \n\nfor i in range(N):\n for j in A:\n if i+B[j] <= N:\n DP[i+B[j]] = max(DP[i]*10+j, DP[i+B[j]])\n\nprint(DP[N+1]) ', 'N, M = map(int, input().split())\n\nA = list(map(int, input().split()))\nB = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nDP = [-1]*(N+1)\nDP[0] = 0 \n\nfor i in range(N):\n for j in A:\n if i+B[j] <= N:\n DP[i+B[j]] = max(DP[i]*10+i,DP[i+B[j]])\n\nprint(DP[N+1]) ', 'N, M = map(int, input().split())\n\nA = list(map(int, input().split()))\nB = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nDP = [-1]*(N+1)\nDP[0] = 0 \n\nfor i in range(N):\n for j in A:\n if i+B[j] <= N:\n DP[i+B[j]] = max(DP[i]*10+j, DP[i+B[j]])\n\nprint(DP[N]) '] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s032675649', 's468781152', 's844162698'] | [14692.0, 14684.0, 14692.0] | [177.0, 165.0, 177.0] | [262, 261, 260] |
p03128 | u687053495 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['\nfrom heapq import heappop, heappush\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\n\nqueue = []\n\nfor a in A:\n if a == 1:\n heappush(queue, (2, 1))\n elif a == 2:\n heappush(queue, (5, 2))\n elif a == 3:\n heappush(queue, (5, 3))\n elif a == 4:\n heappush(queue, (4, 4))\n elif a == 5:\n heappush(queue, (5, 5))\n elif a == 6:\n heappush(queue, (6, 6))\n elif a == 7:\n heappush(queue, (3, 7))\n elif a == 8:\n heappush(queue, (7, 8))\n elif a == 9:\n heappush(queue, (6, 9))\n\nx, y = heappop(queue)\nmod = N % x\nans = [y] * ((N - N % x) // x)\nbaseX = x\n\nwhile mod != 0:\n ans = ans[1:]\n mod += baseX\n x, y = heappop(queue)\n ans.append(y)\n mod %= x\n\nfor a in sorted(ans, reverse=True):\n print(a, end="")', 'N,M = map(int,input().split())\nA = list(map(int,input().split()))\nweight = [0,2,5,5,4,5,6,3,7,6]\ndp=[-1]*(N+1)\ndp[0] = 0\n\nfor i in range(N+1):\n if dp[i] == -1: continue\n for a in A:\n if i+weight[a]<N+1:\n dp[i+weight[a]] = max(dp[i+weight[a]],dp[i]*10+a)\n print(dp)\n\nprint(dp[-1])', '\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nnumbers = [0,2,5,5,4,5,6,3,7,6]\n\n\ndp = ["-" for i in range(11000)]\ndp[0] = ""\n\ndef cal(x, y):\n lenx = len(x)\n leny = len(y)\n \n if lenx > leny:\n return x\n if leny > lenx:\n return y\n \n return max(x, y)\n\nfor i in range(N):\n if dp[i] == "-": \n continue\n\n for j in range(M):\n num = numbers[A[j]]\n dp[i+num] = cal(dp[i] + str(A[j]), dp[i+num])\n\nprint(dp[N])'] | ['Runtime Error', 'Runtime Error', 'Accepted'] | ['s412485094', 's615903934', 's826589306'] | [4084.0, 135472.0, 30196.0] | [24.0, 2011.0, 161.0] | [746, 294, 445] |
p03128 | u690536347 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\n*A, = map(int, input().split())\n\ndp = [""] * (N+1)\nd = {\n 1: 2,\n 2: 5,\n 3: 5,\n 4: 4,\n 5: 5,\n 6: 6,\n 7: 3,\n 8: 7,\n 9: 6\n}\n\nc = [(i, d[i]) for i in A]\nc.sort(key=lambda x:(-x[1], -x[0]))\ndp[0] = ""\ndp[1] = ""\n\nfor i in range(2, N+1):\n for n, cost in c:\n if i-cost<0: continue\n a = int(dp[i]) if dp[i] else 0\n b = int(str(n) + dp[i-cost])\n if a<b:\n dp[i] = str(n) + dp[i-cost]\n\na = 0\nfor s in dp[N]:\n a+= d[int(s)]\n\nif a==N:\n print(dp[N])', 'n,m=map(int,input().split())\n*a,=map(int,input().split())\n\ncost={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}\ndp=[-1]*(n+1)\nv=[0]*(n+1)\n\ndp[0]=0\nfor i in range(1,n+1):\n for j in range(10)[::-1]:\n if not j in a or i<cost[j]:continue\n if dp[i]<dp[i-cost[j]]+1:\n dp[i]=dp[i-cost[j]]+1\n v[i]=j\n\np=n\nwhile p!=0:\n print(v[p],end="")\n p-=cost[v[p]]\nprint()'] | ['Wrong Answer', 'Accepted'] | ['s376641137', 's979620808'] | [23024.0, 4316.0] | [2105.0, 86.0] | [543, 386] |
p03128 | u692453235 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['from collections import defaultdict\nfrom itertools import product, permutations, combinations, combinations_with_replacement\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nL = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}\nD = defaultdict(int)\n\nfor i in A:\n if D[L[i]] < i:\n D[L[i]] = i\n\nNums = sorted((D.keys()))\n\nsup = N//Nums[0]\nE = defaultdict(int)\nFlag = False\n\nfor i in range(Nums[-1]):\n base = (max(sup-Nums[-1], 0) + i) * Nums[0]\n if base == N:\n E[Nums[0]] += sup-i\n break\n for cwr in combinations_with_replacement([0]+Nums[1:], Nums[0]):\n if base + sum(cwr) == N:\n E[Nums[0]] += sup-i\n for j in cwr:\n if j != 0:\n E[j] += 1\n Flag = True\n break\n if Flag:\n break\n\nans = ""\nfor i, x in E.items():\n ans += str(D[i])*x\n\nprint(*sorted(list(ans), reverse=True), sep="")', 'from collections import defaultdict\nfrom itertools import product, permutations, combinations, combinations_with_replacement\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nL = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}\nD = defaultdict(int)\n\nfor i in A:\n if D[L[i]] < i:\n D[L[i]] = i\n\nNums = sorted((D.keys()))\n\nsup = N//Nums[0]\nE = defaultdict(int)\nFlag = False\n\nfor i in range(Nums[-1]):\n base = (max(sup-Nums[-1]+1, 0) + i) * Nums[0]\n if base == N:\n E[Nums[0]] += sup-i\n break\n for cwr in combinations_with_replacement([0]+Nums[1:], Nums[0]):\n if base + sum(cwr) == N:\n E[Nums[0]] += sup-i\n for j in cwr:\n if j != 0:\n E[j] += 1\n Flag = True\n break\n if Flag:\n break\n\nans = ""\nfor i, x in E.items():\n ans += str(D[i])*x\n\nprint(ans, D, Nums, E)\nprint(*sorted(list(ans), reverse=True), sep="")', 'from collections import defaultdict\n\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nL = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}\nD = defaultdict(int)\n\nfor i in A:\n if D[L[i]] < i:\n D[L[i]] = i\n\nINF = float("inf")\ndp = [-INF]*(N+1)\ndp[0] = 0\n\nfor i in range(1, N+1):\n for j in D.keys():\n if i-j >= 0:\n dp[i] = max(dp[i], dp[i-j] + 1)\n else:\n dp[i] = max(dp[i], -INF)\n\nans = ""\ntemp = N\n\n\nfor i, x in sorted(D.items(), key=lambda x: x[1], reverse=True):\n while temp - i >= 0 and dp[temp-i] == dp[temp] - 1:\n ans += str(x)\n temp -= i\n\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s572956339', 's761110129', 's274662133'] | [9468.0, 9524.0, 9560.0] | [31.0, 35.0, 51.0] | [858, 883, 646] |
p03128 | u695811449 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\nsys.setrecursionlimit(10**9)\n\nN,M=map(int,input().split())\nA=list(map(int,input().split()))\nM=[0,2,5,5,4,5,6,3,7,6]\n\ndef match(i):\n ANS=0\n for s in str(i):\n ANS+=M[int(s)]\n\n return ANS\n \nANSLIST=set()\ndef dfs(i,NOW):\n if NOW==N:\n L=sorted(list(i),reverse=True)\n \n x=int(("".join(L)))\n ANSLIST.add(x)\n\n if len(ANSLIST)>=500:\n #print(ANSLIST)\n print(max(ANSLIST))\n sys.exit()\n elif NOW>N:\n return\n else:\n for a in A:\n dfs(i+str(a),NOW+M[a])\n\n\nA.sort(reverse=True)\n#print(A)\nA.sort(key=lambda x:M[x])\n#print(A)\n\ndfs("",0)', 'import sys\nsys.setrecursionlimit(10**9)\n\nN,M=map(int,input().split())\nA=list(map(int,input().split()))\nM=[0,2,5,5,4,5,6,3,7,6]\n\n\n\nSET_A=set(A)\n\nANSLIST=[0]\ndef dfs(i,NOW):\n if ANSLIST[0]!=0:\n return\n ANS=0\n if NOW==N:\n L=sorted(list(i),reverse=True)\n #print(L)\n \n ANSLIST[0]=int(("".join(L)))\n return\n\n elif NOW>N:\n return \n else:\n for a in A:\n dfs(i+str(a),NOW+M[a])\n\n\nA.sort(reverse=True)\nA.sort(key=lambda x:M[x])\ndfs("",0)\n\nx=ANSLIST[0]\nstx=str(x)\nfrom collections import Counter\ncounter=Counter(stx)\n\n\nimport itertools\nfor i,j,k in list(itertools.combinations(range(1,10),3)):\n for l,m,n in list(itertools.combinations(range(1,10),3)):\n if i in SET_A and j in SET_A and k in SET_A and l in SET_A and m in SET_A and n in SET_A and M[i]+M[j]+M[k]==M[l]+M[m]+M[n] and \\\n counter[str(i)]>0 and counter[str(j)]>0 and counter[str(k)]>0 and (n>k or (n==k and m>j) or (n==k and m==j and l>i)):\n x=min(counter[str(i)],counter[str(j)],counter[str(k)])\n counter[str(i)]-=x\n counter[str(j)]-=x\n counter[str(k)]-=x\n counter[str(l)]+=x\n counter[str(m)]+=x\n counter[str(n)]+=x\n\nfor i,j in list(itertools.combinations(range(1,10),2)):\n for l,m in list(itertools.combinations(range(1,10),2)):\n if i in SET_A and j in SET_A and l in SET_A and m in SET_A and M[i]+M[j]==M[l]+M[m] and \\\n counter[str(i)]>0 and counter[str(j)]>0 and (m>j or (m==j and l>i)):\n x=min(counter[str(i)],counter[str(j)])\n counter[str(i)]-=x\n counter[str(j)]-=x\n\n counter[str(l)]+=x\n counter[str(m)]+=x\n\nfor i in range(1,10):\n for l in range(1,10):\n if i in SET_A and l in SET_A and l>i and M[i]==M[l] and counter[str(i)]>0:\n counter[str(l)]+=counter[str(i)]\n counter[str(i)]=0\n\n\n\nANS=""\nfor i in range(9,-1,-1):\n ANS+=str(i)*counter[str(i)]\n\nprint(ANS)\n\n'] | ['Wrong Answer', 'Accepted'] | ['s562300928', 's238499191'] | [20456.0, 20168.0] | [2105.0, 62.0] | [654, 2153] |
p03128 | u721316601 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["def search(N, idx):\n global a, M, count\n\n if N == 0:\n return True\n elif N < 0:\n return False\n elif idx == M:\n return False\n\n loop = N // a[idx][0]\n for i in range(loop, -1, -1):\n flag = search(N-a[idx][0]*i, idx+1)\n if flag:\n if i:\n count.append([a[idx][1], i])\n return True\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\nx = [2,5,5,4,5,6,3,7,6]\na = [[x[A[i]-1],i] for i in range(M)]\ncount = []\na.sort()\n\nsearch(N, 0)\n\nnums = [[A[count[i][0]], count[i][1]] for i in range(len(count))]\n\nnums.sort(reverse=True)\n\nfor i in range(len(nums)):\n print(str(nums[i][0]) * nums[i][1], end='')", "a = [2, 5, 5, 4, 5, 6, 3, 7, 6]\nN, M = list(map(int, input().split()))\nA = sorted(list(map(int, input().split())), reverse=True)\nB = sorted([a[i-1] for i in A])\n\ndp = [-1] * (N+1)\nfor b in B:\n dp[b] = 1\n\nfor i in range(1, N+1):\n for b in B:\n if i < b:\n break\n else:\n dp[i] = max(dp[i], dp[i-b]+1)\ndigit = dp[-1]\n\nfor n in A:\n x = a[n-1]\n while dp[N-x] == digit-1:\n print(n, end='')\n N -= x\n digit -= 1\n if N == x:\n print(n, end='')\n N -= x", "def search(N, idx):\n global a, M, count\n\n if N == 0:\n return True\n elif N < 0:\n return False\n elif idx == M:\n return False\n\n loop = N // a[idx][0]\n for i in range(loop, -1, -1):\n flag = search(N-a[idx][0]*i, idx+1)\n if flag:\n if i:\n count.append([a[idx][1], i])\n return True\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nif 6 in A and 9 in A:\n A.remove(6)\n\nif 5 in A or 3 in A:\n if 2 in A:\n A.remove(2)\n if 5 in A and 3 in A:\n A.remove(3)\n\nx = [2,5,5,4,5,6,3,7,6]\na = [[x[A[i]-1],i] for i in range(len(A))]\ncount = []\na.sort()\n\nsearch(N, 0)\n\nnums = [[A[count[i][0]], count[i][1]] for i in range(len(count))]\n\nnums.sort(reverse=True)\n\nfor i in range(len(nums)):\n print(str(nums[i][0]) * nums[i][1], end='')", "a = [2, 5, 5, 4, 5, 6, 3, 7, 6]\nN, M = list(map(int, input().split()))\nA = sorted(set(list(map(int, input().split()))), reverse=True)\nB = sorted([a[i-1] for i in A])\n\ndp = [-1] * (N+1)\nfor b in B:\n dp[b] = 1\n\nfor i in range(1, N+1):\n for b in B:\n if i < b:\n break\n else:\n dp[i] = max(dp[i], dp[i-b]+1)\ndigit = dp[-1]\n\nfor n in A:\n x = a[n-1]\n while dp[N-x] == digit-1:\n print(n, end='')\n N -= x\n digit -= 1\n if N == x:\n print(n, end='')\n N -= x", "def search(N, idx):\n global a, M, count\n\n if N == 0:\n return True\n elif N < 0:\n return False\n elif idx == M:\n return False\n\n loop = N // a[idx][0]\n for i in range(loop, -1, -1):\n flag = search(N-a[idx][0]*i, idx+1)\n if flag:\n if i:\n count.append([a[idx][1], i])\n return True\n\nN, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\nif 6 in A and 9 in A:\n A.remove(6)\n\nif 5 in A or 3 in A:\n if 2 in A:\n A.remove(2)\n if 5 in A and 3 in A:\n A.remove(3)\nM = len(A)\nx = [2,5,5,4,5,6,3,7,6]\na = [[x[A[i]-1],i] for i in range(M)]\ncount = []\na.sort()\n\nsearch(N, 0)\n\nnums = [[A[count[i][0]], count[i][1]] for i in range(len(count))]\n\nnums.sort(reverse=True)\n\nfor i in range(len(nums)):\n print(str(nums[i][0]) * nums[i][1], end='')", 'N, M = list(map(int, input().split()))\nA = list(map(int, input().split()))\n\ndp = [0] * (N+1)\n\nt = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\nfor i in range(1, N+1):\n for a in A:\n if 0 <= i-t[a]: \n if dp[i-t[a]] == 0 and i-t[a] > 0: continue\n dp[i] = max(dp[i], dp[i-t[a]]*10+a)\nprint(dp[N])'] | ['Wrong Answer', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Wrong Answer', 'Accepted'] | ['s226553839', 's495961512', 's765705192', 's823109765', 's904545502', 's466490481'] | [3064.0, 4276.0, 3192.0, 4196.0, 3064.0, 14388.0] | [18.0, 69.0, 19.0, 66.0, 18.0, 163.0] | [704, 525, 852, 530, 857, 315] |
p03128 | u726615467 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\ntab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA_cmp = {}\nfor Ai in sorted(A):\n A_cmp[tab[Ai]] = Ai\nA = list(A_cmp.values())\nA = A[::-1]\n# print("#", A)\n\nmemo = [None] * (N + 1)\nmemo[0] = 0\n\nimport sys\nsys.setrecursionlimit(100000)\n\ndef dp(X):\n if memo[X] != None: return memo[X]\n if X < 0: return -(1000000007)\n #\n rets = []\n for i, Ai in enumerate(A):\n rets.append(dp(X - tab[Ai]) + 1)\n #\n ret = max(rets)\n memo[X] = ret\n return ret\n\nans_len = dp(N)\n\nN_tmp = N\nans = \'\'\nfor i in range(ans_len):\n for j, Aj in enumerate(A):\n if j < j_str: continue\n if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):\n ans += str(Aj)\n N_tmp -= tab[Aj]\n break\n\nprint(ans)\n', "N, M = map(int, input().split())\nA = list(map(int, input().split()))\n\ntab = [6, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nA_cmp = {}\nfor Ai in sorted(A):\n A_cmp[tab[Ai]] = Ai\nA = list(A_cmp.values())\nA.sort(key=lambda x: -x)\n\nmemo = [None] * (N + 1)\nmemo[0] = 0\n\nimport sys\nsys.setrecursionlimit(100000)\n\ndef dp(X):\n if X < 0: return -(1000000007)\n if memo[X] != None: return memo[X]\n #\n rets = []\n for i, Ai in enumerate(A):\n rets.append(dp(X - tab[Ai]) + 1)\n #\n ret = max(rets)\n memo[X] = ret\n return ret\n\nans_len = dp(N)\n\nN_tmp = N\nans = ''\nfor i in range(ans_len):\n for j, Aj in enumerate(A):\n if dp(N_tmp) - 1 == dp(N_tmp - tab[Aj]):\n ans += str(Aj)\n N_tmp -= tab[Aj]\n break\n\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s583171657', 's410398153'] | [4980.0, 4980.0] | [46.0, 68.0] | [791, 756] |
p03128 | u729133443 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["n,m,*a=map(int,open(0).read().split())\nd=[0]*n*9\nfor i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)\nprint(d[n])", 'n,m,*a=map(int,open(0).read().split())\nd=[0]*n*9\nfor i in range(n):\n for j in a:c=i+(0,2,5,5,4,5,6,3,7,6)[j];d[c]=max(d[c],(d[i]*10+j)*(d[i]or i<1))\nprint(d[n])', "n,m,*a=map(int,open(0).read().split())\nd=[0]+[-1]*n*9\nfor i in range(n):d[i+1]=max(j+d[i-int('0144345265'[j])]*10for j in a)\nprint(d[n])"] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s101914378', 's760930438', 's710744146'] | [15028.0, 10640.0, 15092.0] | [135.0, 2112.0, 137.0] | [131, 160, 136] |
p03128 | u733814820 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['# ABC 118 D\n\ndef resolve():\n N, M = map(int, input().split())\n A = list(map(int, input().split()))\n A.sort(reverse=True)\n\n costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n dp = [0] * (N+1)\n for i in range(1, N+1):\n for a in A:\n if i - costs[a] < 0:\n continue\n dp[i] = max(dp[i-costs[a]] + 1, dp[i])\n\n ans = ""\n remain = dp[N]\n match = N\n\n while match > 0:\n for a in A:\n if match - costs[a] < 0 or match - costs[a] == 1:\n continue\n\n if dp[match-costs[a]] == remain-1:\n ans += str(a)\n match -= costs[a]\n remain -= 1\n break\n\n print(ans)\n\n\nif __name__ == "__main__":\n resolve()\n', '# ABC 118 D\n\ndef resolve():\n N, M = map(int, input().split())\n A = list(map(int, input().split()))\n A.sort(reverse=True)\n\n costs = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\n dp = [-1] * (N+1)\n dp[0] = 0\n for i in range(1, N+1):\n for a in A:\n if i - costs[a] < 0:\n continue\n dp[i] = max(dp[i-costs[a]] + 1, dp[i])\n\n ans = ""\n remain = dp[N]\n match = N\n\n minCosts = 10\n for a in A:\n minCosts = min(minCosts, costs[a])\n\n while match > 0:\n for a in A:\n if match - costs[a] < 0 or 1<= match - costs[a] < minCosts:\n continue\n\n if dp[match-costs[a]] == remain-1:\n ans += str(a)\n match -= costs[a]\n remain -= 1\n break\n\n print(ans)\n\n\nif __name__ == "__main__":\n resolve()\n'] | ['Time Limit Exceeded', 'Accepted'] | ['s074174035', 's516473124'] | [3388.0, 3388.0] | [2104.0, 67.0] | [750, 853] |
p03128 | u761320129 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["from collections import defaultdict\nfrom copy import copy\n\nN,M = map(int,input().split())\nA = list(map(int,input().split()))\n\nms = [2,5,5,4,5,6,3,7,6]\ndic = defaultdict(lambda: 0)\nfor a in A:\n dic[ms[a-1]] = max(dic[ms[a-1]], a)\n\nsd = sorted(dic.items())\n\ndp = [None] * (N+1)\ndp[0] = defaultdict(lambda: 0)\n\nfor i in range(sd[0][0], N+1):\n cands = []\n for l,a in sd:\n if i-l < 0: break\n if dp[i-l] is None: continue\n cands.append(copy(dp[i-l]))\n cands[-1][a] += 1\n if not cands: continue\n max_v = 0\n max_i = -1\n for i,cand_dic in enumerate(cands):\n tmp_s = ''\n for a,n in sorted(cand_dic.items(), reverse=True):\n tmp_s += str(a) * n\n tmp_v = int(tmp_s)\n if tmp_v > max_v:\n max_v = tmp_v\n max_i = i\n dp[i] = cands[i]\n\nans = ''\nfor a,n in sorted(dp[-1].items(), reverse=True):\n ans += str(a) * n\nprint(ans)", "from collections import defaultdict\nfrom copy import copy\n\nN,M = map(int,input().split())\nA = list(map(int,input().split()))\n\nms = [2,5,5,4,5,6,3,7,6]\ndic = defaultdict(lambda: 0)\nfor a in A:\n dic[ms[a-1]] = max(dic[ms[a-1]], a)\n\nsd = sorted(dic.items())\n\ndp = [None] * (N+1)\ndp[0] = defaultdict(lambda: 0)\n\nfor i in range(sd[0][0], N+1):\n cands = []\n least_len = -1\n for l,a in sd:\n if i-l < 0: break\n if dp[i-l] is None: continue\n if cands and sum(dp[i-l].values())+1 < least_len:\n continue\n cands.append(copy(dp[i-l]))\n cands[-1][a] += 1\n least_len = sum(cands[-1].values())\n if not cands: continue\n max_v = 0\n max_j = -1\n for j,cand_dic in enumerate(cands):\n tmp_s = ''\n for a,n in sorted(cand_dic.items(), reverse=True):\n tmp_s += str(a) * n\n tmp_v = int(tmp_s)\n if tmp_v > max_v:\n max_v = tmp_v\n max_j = j\n dp[i] = cands[max_j]\n\nans = ''\nfor a,n in sorted(dp[-1].items(), reverse=True):\n ans += str(a) * n\nprint(ans)"] | ['Runtime Error', 'Accepted'] | ['s441373735', 's103015832'] | [3572.0, 7068.0] | [38.0, 1120.0] | [920, 1066] |
p03128 | u774539708 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m=map(int,input().split())\nA=reversed(sorted(map(int,input().split())))\nM=[2,5,5,4,5,6,3,7,6]\nD={}\nE={}\nfor a in A:\n if M[a-1] in D:\n continue\n else:\n D[M[a-1]]=a\n E[a]=M[a-1]\nS=list(reversed(sorted(E)))\n \ndp=[0]*(n+2)\nfor i in range(1,n+2):\n cnt=-1\n for d in D:\n if i-d>=0:\n if dp[i-d]!=-1:\n cnt=max(dp[i-d]+1,cnt)\n dp[i]=cnt \nk=dp[n]\nans=""\n\n\nprint(dp)\nwhile k>0:\n for s in S:\n x=E[s]\n if dp[n-x]==k-1:\n ans+=str(s)\n k-=1\n n-=x\n break\nprint(ans)', 'n,m=map(int,input().split())\nA=reversed(sorted(map(int,input().split())))\nM=[2,5,5,4,5,6,3,7,6]\nD={}\nE={}\nfor a in A:\n if M[a-1] in D:\n continue\n else:\n D[M[a-1]]=a\n E[a]=M[a-1]\nS=list(reversed(sorted(E)))\n \ndp=[0]*(n+2)\nfor i in range(1,n+2):\n cnt=-1\n for d in D:\n if i-d>=0:\n if dp[i-d]!=-1:\n cnt=max(dp[i-d]+1,cnt)\n dp[i]=cnt \nk=dp[n]\nans=""\nprint(E)\n\nwhile k>0:\n for s in S:\n x=E[s]\n if n-x<0:\n continue\n if dp[n-x]==k-1:\n ans+=str(s)\n k-=1\n n-=x\n break\nprint(ans)', 'n,m=map(int,input().split())\nA=reversed(sorted(map(int,input().split())))\nM=[2,5,5,4,5,6,3,7,6]\nD={}\nE={}\nfor a in A:\n if M[a-1] in D:\n continue\n else:\n D[M[a-1]]=a\n E[a]=M[a-1]\nS=list(reversed(sorted(E)))\n \ndp=[0]*(n+2)\nfor i in range(1,n+2):\n cnt=-1\n for d in D:\n if i-d>=0:\n if dp[i-d]!=-1:\n cnt=max(dp[i-d]+1,cnt)\n dp[i]=cnt \nk=dp[n]\nans=""\n\nwhile k>0:\n for s in S:\n x=E[s]\n if n-x<0:\n continue\n if dp[n-x]==k-1:\n ans+=str(s)\n k-=1\n n-=x\n break\nprint(ans)'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s153423998', 's699730819', 's453758133'] | [3560.0, 3412.0, 3412.0] | [72.0, 68.0, 65.0] | [589, 626, 617] |
p03128 | u782685137 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['cost=[0,2,5,5,4,5,6,3,7,6]\nN,M=map(int,input().split())\nA=sorted(map(int,input().split()))\nlowcost_i=A[0];lowcost=cost[A[0]]\nfor a in A:\n if cost[a]<lowcost:lowcost_i=a;lowcost=cost[a]\ns=str(lowcost_i)*(N//lowcost)\nl=N%lowcost\nbefore_l=l\ndisit=0\n\nwhile l>0:\n lll = {a:cost[a] for a in A if cost[a]<=l+lowcost}\n mmm = max(lll.keys())\n if mmm>lowcost_i:\n #print("p")\n s=s[:disit]+str(mmm)+s[disit+1:]\n l-=lll[mmm]-lowcost\n disit+=1\n else:\n #print("E")\n for k in sorted(lll.keys())[::-1]:\n if lll[k]==l+lowcost:\n s=s[:len(s)]+str(k)\n l=0\n break\n #print(s)\n\nprint(s)', "c=[0,2,5,5,4,5,6,3,7,6]\nI=lambda:map(int,input().split())\nN,M=I()\nA=sorted(I())[::-1]\nd=[0]\nfor i in range(N):l=[d[i+1-c[a]]for a in A if i+2>c[a]];d+=[-1 if len(l)==0 else max(l)+1]\nS=''\nT=0\nfor i in range(d[N]):\n for a in A:\n b=c[a]\n if N-T-b>=0 and d[N-T-b]==d[N]-1-i:S+=str(a);T+=b;break\nprint(S)"] | ['Wrong Answer', 'Accepted'] | ['s565584040', 's344001810'] | [3664.0, 3408.0] | [2104.0, 70.0] | [775, 302] |
p03128 | u785578220 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['from operator import itemgetter\ntik = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[8,7],[6,6]]\ndic = {"1":2,"7":3,"4":4,"5":5,"3":5,"2":5,"9":6,"8":7,"6":6}\n\nn,k = map(int, input().split())\nx = list(map(int, input().split()))\ndp = [0]+[-1]*(n+10)\nq = []\nfor i in range(k):\n q.append([x[i],dic[str(x[i])]])\n\nq = sorted(q, key=itemgetter(1), reverse=False)\n\ns = []\np=0\nt = 0\nfor i in range(n):\n for j in range(k):\n if i+q[j][1] <=n:\n if dp[i]!=-1:\n \n if dp[i]==0:\n ko = str(q[j][0])\n dp[i+q[j][1]] = max(str(q[j][0]),str(dp[i+q[j][1]]))\n\n else:\n ko = str(dp[i])+str(q[j][0])\n dp[i+q[j][1]] = max(str(dp[i])+str(q[j][0]), str(dp[i+q[j][1]]))\n #if i+q[j][1] ==n:\n #print(dp[20])\ns = list(dp[n])\ns.sort()\ns = s[::-1]\nprint(\'\'.join(s))\n', 'from operator import itemgetter\ntik = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[8,7],[6,6]]\ndic = {"1":2,"7":3,"4":4,"5":5,"3":5,"2":5,"9":6,"8":7,"6":6}\n\nn,k = map(int, input().split())\nx = list(map(int, input().split()))\ndp = [0]+[-1]*(n+10)\nq = []\nfor i in range(k):\n q.append([x[i],dic[str(x[i])]])\n\nq = sorted(q, key=itemgetter(1), reverse=False)\n\ns = []\np=0\nt = 0\nfor i in range(n):\n for j in range(k):\n if i+q[j][1] <=n:\n if dp[i]!=-1:\n \n if dp[i]==0:\n ko = str(q[j][0])\n dp[i+q[j][1]] = min(str(q[j][0]),str(dp[i+q[j][1]]))\n\n else:\n ko = str(dp[i])+str(q[j][0])\n dp[i+q[j][1]] = min(str(dp[i])+str(q[j][0]), str(dp[i+q[j][1]]))\n #if i+q[j][1] ==n:\n #print(dp[20])\ns = list(dp[n])\ns.sort()\ns = s[::-1]\nprint(\'\'.join(s))\n', 'from operator import itemgetter\ntik = [[1,2],[7,3],[4,4],[5,5],[3,5],[2,5],[9,6],[8,7],[6,6]]\ndic = {"1":2,"7":3,"4":4,"5":5,"3":5,"2":5,"9":6,"8":7,"6":6}\n\nn,k = map(int, input().split())\nx = list(map(int, input().split()))\ndp = [0]+[-1]*(n+10)\nq = []\nfor i in range(k):\n q.append([x[i],dic[str(x[i])]])\n\nq = sorted(q, key=itemgetter(1), reverse=False)\n\ns = []\np=0\nt = 0\nfor i in range(n):\n for j in range(k):\n if i+q[j][1] <=n:\n if dp[i]!=-1:\n \n if dp[i]==0:\n ko = q[j][0]\n dp[i+q[j][1]] = max(q[j][0],dp[i+q[j][1]])\n\n else:\n ko = dp[i]+q[j][0]\n dp[i+q[j][1]] = max(dp[i]*10+q[j][0], dp[i+q[j][1]])\n #if i+q[j][1] ==n:\n #print(dp[20])\ns = list(str(dp[n]))\ns.sort()\ns = s[::-1]\nprint(\'\'.join(s))'] | ['Wrong Answer', 'Wrong Answer', 'Accepted'] | ['s544931583', 's801052017', 's803884567'] | [12008.0, 3804.0, 14708.0] | [215.0, 191.0, 229.0] | [889, 889, 856] |
p03128 | u794543767 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['\ndef get_input():\n N,K = [int(_) for _ in input().split()]\n S = [int(_) for _ in list(input())]\n return N,K,S\n\ndef solve(N,K,S):\n length = len(S)\n array = count_array(S)\n start_char = S[0]\n ans = find_max(array,K,start_char)\n return ans\n\ndef find_max(array,K,start_char):\n if start_char ==0 and len(array) <= 2 * K:\n return sum(array)\n elif start_char == 1 and len(array) <=2 * K+1 :\n return sum(array)\n else:\n if start_char == 0:\n start,end = 1,2*K+2\n else:\n start,end = 0,2*K+1\n idx = 0\n \n current_sum = sum(array[start:end])\n ret = [current_sum]\n if start_char == 0:\n ret.append(sum(array[0:2*K]))\n ret.append(sum(array[-2*K:]))\n while(1):\n start+=2\n end+=2\n if end > len(array):\n break\n current_sum = current_sum- sum(array[start-2:start]) + sum(array[end-2:end])\n ret.append(current_sum)\n return max(ret)\n \n\ndef count_array(S):\n array = []\n cur_char = S[0]\n cur_val = 1\n for char in S[1:]:\n if cur_char != char:\n array.append(cur_val)\n cur_char = char\n cur_val = 1\n else:\n cur_val+=1\n array.append(cur_val)\n\n return array\n\n\n\n\n\nif __name__ == "__main__":\n N,K,S = get_input()\n ans = solve(N,K,S)\n print(ans)', 'import sys \nRESOURCE_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])\n\ndef get_input():\n N,M = [ int(_) for _ in input().split()]\n A = [int(_) for _ in input().split()]\n return N,M,A\n\n\ndef solve(N,M,A):\n A = sorted(A)[::-1]\n dp = [ -100*N for _ in range(N+1)]\n dp[0] = 0\n for i in range(1,N+1):\n fill(A,dp,i,N)\n print(dp)\n array = find_array(dp,N,A)\n return "".join(map(str,array))\n\ndef fill(A,dp,n,N):\n cand = [ dp[n-num]+1 for num in A if n - num >= 0 ]\n dp[n] = max(cand) if len(cand) > 0 else -100*N\n\ndef find_array(dp,N,A):\n array = []\n sorted_A = sorted(A)\n print(sorted_A )\n current_n = N\n for _ in range(dp[N]):\n for number in sorted_A[::-1]:\n if dp[current_n-RESOURCE_DICT[number]] == dp[current_n]-1:\n array.append(number)\n current_n -= RESOURCE_DICT[number]\n break\n print(array)\n \n return array\n\n\nif __name__ =="__main__":\n N,M,A = get_input()\n ans = solve(N,M,A)\n print(ans)', 'import sys \nRESOURC_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])\n\ndef get_input():\n N,M = [ int(_) for _ in input().split()]\n A = [int(_) for _ in input().split()]\n return N,M,A\n\n\ndef solve(N,M,A):\n dp = [-1 for _ in range(N+1)]\n for i in range(N+1):\n fill(A,dp,i)\n return dp[N]\n\n\ndef count_digit(number,current=0):\n if number == 0:\n return current\n else:\n return count_digit(number//10,current=current+1)\n\ndef fill(A,dp,n):\n cand = []\n for number in A:\n weight = RESOURC_DICT[number]\n if n -weight>=0:\n if n- weight == 0:\n cand.append(number)\n else:\n if dp[n-weight] != -1:\n cand.append(max(\n 10**count_digit(dp[n-weight])*number + dp[n-weight],\n 10 * dp[n-weight] +number )\n )\n else:\n cand.append(-1)\n else:\n cand.append(-1)\n dp[n] = max(cand)\n\n\nif __name__ =="__main__":\n N,M,A = get_input()\n solve(N,M,A)\n print(ans)', 'import sys \nRESOURCE_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])\n\ndef get_input():\n N,M = [ int(_) for _ in input().split()]\n A = [int(_) for _ in input().split()]\n return N,M,A\n\n\ndef solve(N,M,A):\n sorted_A = sorted(A)[::-1]\n dp = fill_dp(N,sorted_A)\n array = find_array(dp,N,sorted_A)\n return "".join(map(str,array))\n\ndef fill_dp(N,A):\n dp = [ -100*N for _ in range(N+1)]\n dp[0] = 0\n for i in range(1,N+1):\n fill(A,dp,i,N)\n return dp\n\ndef fill(A,dp,n,N):\n cand = [ dp[n-RESOURCE_DICT[num]]+1 for num in A if n - RESOURCE_DICT[num] >= 0 ]\n dp[n] = max(cand) if len(cand) > 0 else -100*N\n\ndef find_array(dp,N,sorted_A):\n array = []\n current_n = N\n print(sorted_A)\n for _ in range(dp[N]):\n for number in sorted_A:\n if dp[current_n-RESOURCE_DICT[number]] == dp[current_n]-1:\n array.append(number)\n current_n -= RESOURCE_DICT[number]\n break\n print(array) \n return array\n\n\nif __name__ =="__main__":\n N,M,A = get_input()\n ans = solve(N,M,A)\n print(ans)', 'import sys \nRESOURCE_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])\n\ndef get_input():\n N,M = [ int(_) for _ in input().split()]\n A = [int(_) for _ in input().split()]\n return N,M,A\n\n\ndef solve(N,M,A):\n A = sorted(A)[::-1]\n dp = [ -100*N for _ in range(N+1)]\n dp[0] = 0\n for i in range(1,N+1):\n fill(A,dp,i,N)\n array = find_array(dp,N,A)\n return "".join(map(str,array))\n\ndef fill(A,dp,n,N):\n cand = [ dp[n-num]+1 for num in A if n - num >= 0 ]\n dp[n] = max(cand) if len(cand) > 0 else -100*N\n\ndef find_array(dp,N,A):\n array = []\n sorted_A = sorted(A)\n current_n = N\n for _ in range(dp[N]):\n for number in sorted_A[::-1]:\n if dp[current_n-RESOURCE_DICT[number]] == dp[current_n]-1:\n array.append(number)\n current_n -= RESOURCE_DICT[number]\n break \n return array\n\n\nif __name__ =="__main__":\n N,M,A = get_input()\n ans = solve(N,M,A)\n print(ans)', 'import sys \nRESOURCE_DICT = dict([(k,v) for k,v in zip(range(1,10),[2,5,5,4,5,6,3,7,6])])\n\ndef get_input():\n N,M = [ int(_) for _ in input().split()]\n A = [int(_) for _ in input().split()]\n return N,M,A\n\n\ndef solve(N,M,A):\n sorted_A = sorted(A)[::-1]\n dp = fill_dp(N,sorted_A)\n array = find_array(dp,N,sorted_A)\n return "".join(map(str,array))\n\ndef fill_dp(N,A):\n dp = [ -100*N for _ in range(N+1)]\n dp[0] = 0\n for i in range(1,N+1):\n fill(A,dp,i,N)\n return dp\n\ndef fill(A,dp,n,N):\n cand = [ dp[n-RESOURCE_DICT[num]]+1 for num in A if n - RESOURCE_DICT[num] >= 0 ]\n dp[n] = max(cand) if len(cand) > 0 else -100*N\n\ndef find_array(dp,N,sorted_A):\n array = []\n current_n = N\n for _ in range(dp[N]):\n for number in sorted_A:\n if current_n-RESOURCE_DICT[number] >= 0 and dp[current_n-RESOURCE_DICT[number]] == dp[current_n]-1:\n array.append(number)\n current_n -= RESOURCE_DICT[number]\n break\n return array\n\n\nif __name__ =="__main__":\n N,M,A = get_input()\n ans = solve(N,M,A)\n print(ans)'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s159985338', 's388019042', 's454244189', 's883991562', 's901410151', 's803445543'] | [3184.0, 3572.0, 5700.0, 3700.0, 3444.0, 3700.0] | [18.0, 56.0, 2104.0, 56.0, 54.0, 60.0] | [1436, 1057, 1114, 1124, 1004, 1113] |
p03128 | u798129018 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['n,m = map(int,input().split())\nl = [2,5,5,4,5,6,3,7,6]\nA = list(map(int, input().split()))\nmina = [0,9]\nfor a in A:\n if l[a-1] < mina[1]:\n mina[0] = a\n mina[1] = l[a-1]\n elif l[a-1] == mina[1] and mina[0] < a:\n mina[0] = a\n else:\n continue\nketa = n // mina[1]\nk = keta\nA.sort(reverse=True)\nanslist = [mina[0]]*(keta)\nfor i in range(keta):\n k -= 1\n for a in A:\n if n-l[a-1]>=k*mina[1]:\n n -=l[a-1]\n anslist[i]=a\n break\n else:\n continue\nans = list(map(str,anslist))\nprint("".join(ans))', 'n,m= map(int,input().split())\nA = list(map(int,input().split()))\ncost = [0,2,5,5,4,5,6,3,7,6]\ndp =[-1]*10010\ndp[0]=0\nfor i in range(1,n+1):\n for a in A:\n if i - cost[a] >= 0:\n dp[i] = max(dp[i],a+dp[i-cost[a]]*10)\nprint(dp[n])'] | ['Wrong Answer', 'Accepted'] | ['s133109318', 's508065312'] | [3316.0, 14388.0] | [29.0, 153.0] | [584, 247] |
p03128 | u814986259 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import bisect\nN, M = map(int, input().split())\nA = list(map(int, input().split()))\nnum = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]\nnum = [(i, num[i]) for i in range(10) if i in A]\nnum.sort(key=lambda x: x[0], reverse=True)\nnum.sort(key=lambda x: x[1])\ndp = ["" for i in range(N+1)]\nans = 0\ntmp = set()\nfor x in num:\n if x > N:\n continue\n for i in range(1, N+1-x[1]):\n for n, k in num:\n if i - k in tmp:\n dp[i] = dp[i-k]+str(n)\n tmp.add(i)\n break\n else:\n if i == k:\n dp[i] = str(n)\n tmp.add(k)\n break\n tmp2 = list(dp[N-x[1]])\n tmp2.append(str(x[0]))\n tmp2.sort(reverse=True)\n ans = max(int("".join(map(str, tmp2))), ans)\nprint(ans)\n', 'def main():\n N, M = map(int, input().split())\n A = set(map(int, input().split()))\n\n\n cost = [-1, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n B = []\n for i in range(1, 10):\n if i in A:\n B.append((cost[i], i))\n\n B = B[::-1]\n dp = [[-1, -1] for i in range(N+1)]\n dp[0][0] = 0\n for i in range(1, N+1):\n for x, y in B:\n if i >= x and dp[i-x][0] >= 0:\n if dp[i][0] < dp[i-x][0] + 1:\n dp[i][0] = dp[i-x][0] + 1\n dp[i][1] = y\n id = N\n ans = []\n # print(dp)\n while(id > 0):\n ans.append(dp[id][1])\n id -= cost[dp[id][1]]\n ans.sort(reverse=True)\n print("".join(map(str, ans)))\nmain()'] | ['Runtime Error', 'Accepted'] | ['s827760998', 's813420581'] | [3188.0, 4692.0] | [18.0, 51.0] | [791, 704] |
p03128 | u820351940 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ['import sys\nsys.setrecursionlimit(1000000)\n\nn, m = map(int, input().split())\na = list(map(int, input().split()))\ncost = [None, 2, 5, 5, 4, 5, 6, 3, 7, 6]\n\ndp = [None] * (n + 1)\ndef dfs(at):\n if dp[at] is not None:\n return dp[at]\n r = max([0] + [dfs(at - cost[v]) * 10 + v for v in a if at - cost[v] >= 0])\n dp[at] = r\n return r\n\n\nprint(dfs(n))\n', 'import sys\nsys.setrecursionlimit(1000000)\n\nn, m = map(int, input().split())\na = list(map(int, input().split()))\ncost = [float("inf"), 2, 5, 5, 4, 5, 6, 3, 7, 6]\nmincost = min(cost)\n\ndp = [None] * (n + 1)\ndef dfs(at):\n if at < 0:\n return -1\n if at == 0:\n return 0\n if dp[at] is not None:\n return dp[at]\n r = max(dfs(at - cost[v]) * 10 + v for v in a)\n dp[at] = r\n return r\n\n\nprint(dfs(n))\n'] | ['Wrong Answer', 'Accepted'] | ['s741866502', 's762019856'] | [22772.0, 21620.0] | [158.0, 142.0] | [362, 427] |
p03128 | u820839927 | 2,000 | 1,048,576 | Find the largest integer that can be formed with exactly N matchsticks, under the following conditions: * Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9). * The number of matchsticks used to form digits 1, 2, 3, 4, 5, 6, 7, 8, 9 should be 2, 5, 5, 4, 5, 6, 3, 7, 6, respectively. | ["import os, sys, re, math\n\nN,M = list(map(int,input().split(' ')))\nA = list(map(int,input().split(' ')))\nprint(A)\n\nmatch = [-1,2,5,5,4,5,6,3,7,6]\nmemo = {}\n\ndef doit(m):\n if m in memo:\n return memo[m]\n\n max_v = 0\n for a in A:\n if m - match[a] == 0:\n max_v = max(int(max_v), int(str(a)))\n elif m > match[a]:\n tmp = doit(m - match[a])\n if tmp != '0':\n max_v = max(int(max_v), int(str(a) + doit(m - match[a])))\n\n memo[m] = str(max_v)\n return str(max_v)\n\nprint(doit(N))\n", "import os, sys, re, math\n\nN,M = list(map(int,input().split(' ')))\nA = list(map(int,input().split(' ')))\nprint(A)\n\nmatch = [-1,2,5,5,4,5,6,3,7,6]\nmemo = {}\n\ndef doit(m):\n if m in memo:\n return memo[m]\n\n max_v = '-9'\n for a in A:\n if m - match[a] == 0:\n max_v = max(max_v, str(a), key=lambda x: int(x))\n elif m - match[a] >= 0:\n max_v = max(max_v, doit(m - match[a]) + str(a), key=lambda x: int(x))\n if max_v != '':\n memo[m] = str(max_v)\n return str(max_v)\n else:\n return '-9'\n\nprint(doit(N))\n", "import os, sys, re, math\n\nN,M = list(map(int,input().split(' ')))\nA = list(map(int,input().split(' ')))\nprint(A)\n\nmatch = [-1,2,5,5,4,5,6,3,7,6]\nmemo = {}\n\ndef doit(m):\n if m in memo:\n return memo[m]\n if m <= 0:\n return ''\n\n max_v = '0'\n for a in A:\n tmp = doit(m - match[a])\n if m >= match[a] and tmp is not None:\n max_v = max(max_v, str(a) + doit(m - match[a]),key= lambda x: int(x))\n\n if max_v != '0':\n memo[m] = max_v\n return max_v\n else:\n return None\n\nprint(doit(N))\n", 'import os, sys, re, math\nsys.setrecursionlimit(100000)\nN,M = list(map(int,input().split(\' \')))\nA = list(map(int,input().split(\' \')))\n\nmatch = [100,2,5,5,4,5,6,3,7,6]\nmemo = {}\n\ndef doit(m):\n if m in memo:\n return memo[m]\n if m == 0:\n return ""\n\n ret = None\n for a in A:\n tmp = None\n if m - match[a] >= 0:\n tmp = doit(m - match[a])\n if tmp is not None:\n tmp = str(a) + tmp\n if ret is not None:\n if len(ret) < len(tmp) or (len(ret) == len(tmp) and tmp > ret):\n ret = tmp\n else:\n ret = tmp\n\n memo[m] = ret\n return ret\n\nprint(doit(N))\n'] | ['Runtime Error', 'Runtime Error', 'Runtime Error', 'Accepted'] | ['s245545769', 's334402184', 's916595327', 's675707453'] | [7960.0, 7836.0, 7904.0, 33836.0] | [302.0, 347.0, 352.0, 130.0] | [549, 570, 550, 705] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.