A - 内積の計算 / Dot Product Calculation Editorial by admin
DeepSeek V3Overview
Given the components of two 7-dimensional vectors \(\mathbf{a}\) and \(\mathbf{b}\), the problem asks to compute their dot product.
Analysis
The dot product is the sum of the products of corresponding components of two vectors of the same dimension. Since this problem deals with 7-dimensional vectors, we need to sum up the products of all 7 pairs of corresponding components. No particularly complex algorithm is needed — we can solve this by simply computing the product of each pair of components and summing them up.
Algorithm
- Read the 7 components of vector \(\mathbf{a}\) from the first line
- Read the 7 components of vector \(\mathbf{b}\) from the second line
- For each index \(i\) (\(0 \leq i < 7\)), compute \(a_i \times b_i\)
- Sum all the products and output the result
Complexity
- Time complexity: \(O(1)\)
- Only 7 multiplications and 6 additions (a constant number of operations) are needed
- Space complexity: \(O(1)\)
- Only two arrays (each with 7 elements) are used to store the vectors
Implementation Notes
Use
input().split()to split the input by spaces, convert toint, and store in a listUse the
mapfunction and alambdaexpression to multiply the corresponding elements of the two listsUse the
sumfunction to compute the total of all multiplication resultsThis implementation effectively utilizes Python’s built-in functions to write concise code
Source Code
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
print(sum(map(lambda x, y: x * y, a, b)))
This editorial was generated by deepseekv3.
posted:
last update: