We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Python
- Itertools
- Maximize It!
- Discussions
Maximize It!
Maximize It!
Sort by
recency
|
1116 Discussions
|
Please Login in order to post a comment
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))
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)
using sparse DP approach