Easily Broadcastable Tensors
시간 제한1초메모리 제한2048 MB
두 차원 크기 수열이 주어질 때, 뒤에서부터 정렬한 각 쌍이 서로 같거나 둘 중 하나가 1이 되도록 1을 최소 개수만큼 끼워 넣는 문제이다.
문제
Little I is learning to use PyTorch. It is a very popular Python library for machine learning training.
Little I noticed that PyTorch has a mechanism for tensor operations called "broadcasting". You can think of tensors as multidimensional arrays. For a -dimensional tensor , we use a sequence of length denoted as to represent the lengths of its dimensions, meaning is a tensor of size .
For two tensors and , with dimensions and , respectively, and are easily broadcastable if and only if the following property holds:
For any integer , either or at least one of and is .
Now, Little I has two tensors with dimensions and , and they may not be easily broadcastable.
To make them easily broadcastable, Little I can use several operations (or none), where each operation modifies the sequence or as follows:
Choose or , and insert a at any position in the chosen sequence.
Little I wants to know the minimum number of operations required to make the two tensors easily broadcastable.
입력
The first line contains two integers and () representing the dimensions of the two tensors.
The second line contains integers ( describing the length of each dimension for the first tensor.
The third line contains integers ( describing the length of each dimension for the second tensor.
출력
Print a line with a single integer: the minimum number of insertions of required to make the two tensors easily broadcastable.
힌트
In the example, inserting a before the second position in sequence (resulting in 4 1 2) makes the two tensors easily broadcastable.