#P10043. [CCPC 2023 北京市赛] 广播
[CCPC 2023 北京市赛] 广播
Problem Description
Xiao I is learning to use Pytorch. It is a very popular Python library for machine learning training.
Xiao I noticed that Pytorch has a mechanism for tensor operations called "broadcast". You can think of a tensor as a high-dimensional array. For a -dimensional tensor , we use a sequence of length , , to represent the size of each dimension. That is, is a tensor of shape .
For two tensors and , suppose their dimensions are and respectively. We say and are broadcastable if and only if the following property holds:
- For any integer , either , or at least one of and is .
Now Xiao I has two tensors with dimensions and . They are not necessarily broadcastable.
So, Xiao I can use Pytorch built-in functions to perform some operations (possibly none). In each operation, he modifies sequence or as follows:
- Choose or , and insert a at any position in the chosen sequence.
Xiao I wants to know the minimum number of operations needed to make the two tensors broadcastable.
Input Format
The first line contains two integers , representing the number of dimensions of the two tensors.
The second line contains integers , describing the length of each dimension of the first tensor.
The third line contains integers , describing the length of each dimension of the second tensor.
Output Format
Output one integer in a single line, representing the minimum number of inserted 's needed to make the two tensors broadcastable.
4 2
2 1 3 2
4 2
1
Hint
Insert a before the second position of sequence (getting 4 1 2), and then the two tensors will become broadcastable.
Translated by ChatGPT 5