Submission #20505288


Source Code Expand

import sys
from collections import defaultdict, Counter, deque
from itertools import permutations, combinations, product, combinations_with_replacement, groupby, accumulate
import operator
from math import sqrt, gcd, factorial
#from math import isqrt, prod,comb  # python3.8用(notpypy)
#from bisect import bisect_left,bisect_right
from functools import lru_cache,reduce
#from heapq import heappush,heappop,heapify,heappushpop,heapreplace
#import numpy as np
#import networkx as nx
#from networkx.utils import UnionFind
#from numba import njit, b1, i1, i4, i8, f8
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, NegativeCycleError
#numba例 @njit(i1(i4[:], i8[:, :]),cache=True) 引数i4配列、i8 2次元配列,戻り値i1
sys.setrecursionlimit(10**4+10)
def input(): return sys.stdin.readline().rstrip()
def divceil(n, k): return 1+(n-1)//k  # n/kの切り上げを返す
def yn(hantei, yes='Yes', no='No'): print(yes if hantei else no)

@lru_cache
def solve(n,A):
    if n==0:
        return 0
    elif n<=0:
        return -float('INF')
    match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
    ans=[]
    for AA in A:
        ans.append(solve(n-match[AA],A)*10+AA)
    return max(ans)

def main():
    mod = 10**9+7
    mod2 = 998244353
    n,m=map(int, input().split())
    A=tuple(map(int, input().split()))
    print(solve(n,A))

if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task D - Match Matching
User ansain
Language Python (3.8.2)
Score 400
Code Size 1500 Byte
Status AC
Exec Time 115 ms
Memory 18240 KiB

Judge Result

Set Name All Sample
Score / Max Score 400 / 400 0 / 0
Status
AC × 29
AC × 3
Set Name Test Cases
All 0_random_1, 0_random_2, 0_random_3, 0_random_4, 0_random_5, 0_random_6, 0_random_7, 0_random_8, 1_normal_1, 1_normal_2, 1_normal_3, 1_normal_4, 1_normal_5, 1_normal_6, 2_corner_1, 2_corner_2, 2_corner_3, 2_corner_4, 2_corner_5, 2_corner_6, 3_hand_1, 3_hand_2, 3_hand_3, 3_hand_4, 3_hand_5, 3_hand_6, sample_01, sample_02, sample_03
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
0_random_1 AC 28 ms 9416 KiB
0_random_2 AC 21 ms 9392 KiB
0_random_3 AC 31 ms 10036 KiB
0_random_4 AC 70 ms 12444 KiB
0_random_5 AC 84 ms 12676 KiB
0_random_6 AC 61 ms 13264 KiB
0_random_7 AC 25 ms 11408 KiB
0_random_8 AC 27 ms 9652 KiB
1_normal_1 AC 36 ms 10232 KiB
1_normal_2 AC 63 ms 12260 KiB
1_normal_3 AC 43 ms 11144 KiB
1_normal_4 AC 64 ms 16316 KiB
1_normal_5 AC 49 ms 12644 KiB
1_normal_6 AC 48 ms 10720 KiB
2_corner_1 AC 35 ms 10500 KiB
2_corner_2 AC 26 ms 9620 KiB
2_corner_3 AC 50 ms 12108 KiB
2_corner_4 AC 27 ms 9820 KiB
2_corner_5 AC 24 ms 9564 KiB
2_corner_6 AC 31 ms 10092 KiB
3_hand_1 AC 43 ms 11724 KiB
3_hand_2 AC 28 ms 9404 KiB
3_hand_3 AC 23 ms 9252 KiB
3_hand_4 AC 28 ms 9396 KiB
3_hand_5 AC 28 ms 9384 KiB
3_hand_6 AC 115 ms 18240 KiB
sample_01 AC 21 ms 9472 KiB
sample_02 AC 21 ms 9276 KiB
sample_03 AC 27 ms 9396 KiB