Maximize It!

Sort by

recency

|

1078 Discussions

|

  • + 0 comments

    More clear solution

    from itertools import product
    k, m = list(map(int, input().split()))
    
    # f(X) function
    def f(x):
        return x**2
    
    lst = []
    for _ in range(k):
        local_input = list(map(int, input().split()))
        lst.append(local_input[1:])
    
    # Apply f(X) function
    sqared_list = [[f(x) for x in l] for l in lst]
    
    # Generate cartesian product to obtain all possible combinations
    combined = product(*sqared_list)
    max_s = 0
    for c in combined:
        # Get local sum
        local_sum = sum(c)
        
        # Get local mod of m
        local_mod = local_sum % m
        
        # Get the maximized value
        max_s = max(max_s, local_mod)
    print(max_s)
    
  • + 0 comments
    import itertools
    n, m = map(int, input().split())
    l=[]
    for _ in range(n):
        l.append(set(list(map(int, input().split()))[1:]))
    
    combinations = list(itertools.product(*l))  
    
    big_num = 0
    for i in range(len(combinations)):
        big_num = max(sum([x**2 for x in combinations[i]])%m ,big_num)
    print(big_num)
    
  • + 0 comments
    from itertools import product
    n, k = list(map(int, list(input().split())))
    m = []
    #n = int(input())
    for i in range(n):
        m.append(list(map(int, (input().split()[1:]))))
    
    combinations = list(product(*m))
    
    squared_m = []
    semifinal_list = []
    
    for combination in combinations:
        tuples = ()
        for i in combination:
            tuples += (i**2),
        squared_m.append(tuples)
    for i in squared_m:
        semifinal_list.append(sum(i)%k)
    
    print(max(semifinal_list))
    
  • + 0 comments

    Here is my solution

    x = [list(map(str, input().split()))]
    m1, m2 = int(x[0][0]), int(x[0][1])
    x = [list(map(int, input().split())) for _ in range(m1)]
    for z in x:
        z.pop(0)
    pools = list(map(tuple, x))
    elements = [[]]
    for pool in pools:
        elements = [x+[y] for x in elements for y in pool]
    
    S = list([sum(j**2 for j in i) for i in elements])
    Smax = [i%m2 for i in S]
    print(max(Smax))
    
  • + 0 comments
    from itertools import product
    
    K, M = map(int, input().split())
    lists = []
    
    for i in range(K):
        lists.append([int(x)**2 for x in input().split()[1:]])
        
    per = list(product(*lists))
    
    ans = list(map(lambda x: sum(x) % M, per))
    
    print(max(ans))