Maximize It!

Sort by

recency

|

1116 Discussions

|

  • + 0 comments

    Enter your code here. Read input from STDIN. Print output to STDOUT

    k,m = map(int, input().split()) inp_list = []

    for _ in range(k): _, *nums = map(int, input().split()) inp_list.append([x * x % m for x in nums])

    curr_results = {0}

    for li in inp_list: new_results = set() for res in curr_results: for ele in li: new_results.add((res + ele) % m) curr_results = new_results print(max(curr_results))

  • + 0 comments

    from itertools import combinations, product def calc_total(tp): summ =0 for t in tp: summ += t**2 return summ

    lst = [] tmpl = [] n, m = [int(ch) for ch in input().split()]

    print((n,m))

    print(max(lst[0]))

    for i in range(n): tmpl = [int(ch) for ch in input().split()] lst.append(tmpl[1:]) smax =0 groups = list(product(*lst)) for group in groups: tmp = (calc_total(group))%m if tmp > smax: smax = tmp; print(smax)

  • + 0 comments
    from itertools import product
    K,M = map(int,input().split())
    K_lists_squared=[[int(x)**2 for x in input()[2:].split()] for _ in range(K)]
    max_val = max([(sum(t)%M) for t in product(*K_lists_squared)])
    print(max_val)
    
  • + 0 comments
    from itertools import product
    
    K,M=input().split()
    def fx(l1):
        l2=list(map(lambda x:x**2,l1))
        return(sum(l2)%int(M))
    
    lists= [ list(map(int,input().split()))[1:] for _ in range(int(K))]
    combos=list(product(*lists))
    S_max=0
    for comb in combos:
        value=fx(comb)
        if value>S_max:
            S_max=value
    print(S_max)
    
  • + 0 comments

    using sparse DP approach

    k,m = map(int, input().split())
    inp_list = []
    
    for _ in range(k):
        _, *nums = map(int, input().split())
        inp_list.append([x * x % m for x in nums])
    
    curr_results = {0}
    
    for li in inp_list:
        new_results = set()
        for res in curr_results:
            for ele in li:
                new_results.add((res + ele) % m)
        curr_results = new_results
    print(max(curr_results))