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
|
1039 Discussions
|
Please Login in order to post a comment
My solution might look more complicated than the others due to the fact that it contains more lines of code. However it is just code that others wrote in function:
Here is step-by-step explanation: 1. Read input 2. Call find_result function which performs all the neccesary calculations 2.1 Inside find_result function we call product method which creates iterable of cartesian_product, meaning [['a', 'b'], ['c', 'd']] would result into [['a', 'c'], ['a', 'd'], ['b', 'c'], ['b', 'd']] (in our case it is all possible combinations of parameters for math_function) 2.2 We use starmap to pass all possible combinations into math_function and find maximum from obtained results.
Starmap documentation: https://docs.python.org/3/library/itertools.html#itertools.starmap Product documentation: https://docs.python.org/3/library/itertools.html#itertools.product
This line in the instructions is not well written:
The first number in every line is size of the array that follows. WHY!!!!
Whoever wrote that needs to take a course on communications. They may be a good engineer, but they're not good at explaining things in a way that students will understand.
from itertools import product
s=input().split()
q=[]
e=0
for _ in range(int(s[0])):
q.append(list(map(int,input().split())))
for i in list(product(*q)):
a=0
for o in i:
a=o*o+a
if a%int(s[1])>e:
e=a%int(s[1]) print(e) print(e)