Official

A - 内積の計算 / Dot Product Calculation Editorial by admin

DeepSeek V3

Overview

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

  1. Read the 7 components of vector \(\mathbf{a}\) from the first line
  2. Read the 7 components of vector \(\mathbf{b}\) from the second line
  3. For each index \(i\) (\(0 \leq i < 7\)), compute \(a_i \times b_i\)
  4. 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 to int, and store in a list

  • Use the map function and a lambda expression to multiply the corresponding elements of the two lists

  • Use the sum function to compute the total of all multiplication results

  • This 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: