A - 内積の計算 / Dot Product Calculation 解説 by admin
Qwen3-Coder-480BOverview
This is a problem of computing the dot product of 7-dimensional vectors.
Analysis
This problem asks us to compute the dot product \(\mathbf{a} \cdot \mathbf{b} = A_1 \times B_1 + A_2 \times B_2 + \cdots + A_7 \times B_7\) for two 7-dimensional vectors \(\mathbf{a} = (A_1, A_2, \ldots, A_7)\) and \(\mathbf{b} = (B_1, B_2, \ldots, B_7)\).
No particularly complex processing is needed — we simply multiply corresponding components and sum them up. Even a straightforward approach runs sufficiently fast, since the number of computations is only 7 and the constraints are very small.
For example, when \(\mathbf{a} = (1, 2, 3, 4, 5, 6, 7)\) and \(\mathbf{b} = (7, 6, 5, 4, 3, 2, 1)\):
\[ \mathbf{a} \cdot \mathbf{b} = 1 \times 7 + 2 \times 6 + 3 \times 5 + 4 \times 4 + 5 \times 3 + 6 \times 2 + 7 \times 1 = 7 + 12 + 15 + 16 + 15 + 12 + 7 = 84 \]
Algorithm
- First, read two lines of input and store each as a list of integers.
- Compute the product \(A_i \times B_i\) for each component and add it to a running total.
- Output the final total.
Complexity
- Time complexity: \(O(7) = O(1)\) (constant time)
- Space complexity: \(O(7) = O(1)\) (constant space)
Implementation Notes
Since the input consists of space-separated integers, you can easily convert it to a list using
input().split()andmap(int, ...).When accessing elements by index in a loop, be careful not to go out of bounds (in this case, there are always exactly 7 elements, so this is not an issue).
Source Code
a = list(map(int, input().split()))
b = list(map(int, input().split()))
result = 0
for i in range(7):
result += a[i] * b[i]
print(result)
This editorial was generated by qwen3-coder-480b.
投稿日時:
最終更新: