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
|
1070 Discussions
|
Please Login in order to post a comment
I get an answer of 766 for test 10, and I fail. However 766 appears to be the right answer, even when I substitute my code for other's apparently working answers. Broken tests?
k, m = map(int, input().split()) matrix = [] count = 0 def map_square(x): x = i for i in range(k): x= [*map(lambda x: (int(x)**2)%m, input().split())] x.sort() matrix.append(x) matrix.sort(key=lambda x: max(x) )
def calculate_sum_all_elements(matrix:list): if len(matrix) == 1: return max(matrix) else: lst1 = matrix.pop(0) lst2 = matrix.pop(0) lst = [(x+y)%m for x in lst1 for y in lst2] matrix.insert(0, lst) return calculate_sum_all_elements(matrix)
print(max(calculate_sum_all_elements(matrix)))
import itertools
k,m=map(int,input().split())
el_list=[]
for i in range(k):
all_possibility = list(itertools.product(*el_list))
print(max([sum([j**2 for j in i])%m for i in all_possibility]))