

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
長さ の整数列 が与えられます。 また、 の長さ の連続な部分列 と、 の長さ の連続な部分列 が与えられます。
に対して、下記の つのいずれかを行うという操作を、好きな回数( 回でも良い)だけ行うことができます。
- の先頭に任意の整数を つ追加する。
- の先頭の要素を削除する。
- の末尾に任意の整数を つ追加する。
- の末尾の要素を削除する。
ただし、各操作の前後において、 は の空でない連続な部分列でなければなりません。 を と一致させるために行う操作回数の最小値を求めてください。 なお、本問題の制約下において、操作の繰り返しによって と を必ず一致させられることが証明できます。
連続な部分列とは?
数列 が数列 の連続な部分列であるとは、 を満たす整数 が存在して、 すべての について、 が成り立つことです。
制約
- と は、 の連続な部分列
- 入力はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
7 3 1 4 1 5 7 2 2 3 1 3 1 5 7
出力例 1Copy
3
下記の手順で操作すると、 が の空でない連続な部分列であるという条件を満たしたまま、 を に一致させることが出来ます。
- まず、 の先頭の要素を削除する。その結果、 となる。
- 次に、 の末尾に を追加する。その結果、 となる。
- さらに、 の 末尾に を追加する。その結果、 となり、 は と一致する。
上記の手順の操作回数は 回であり、これが考えられる最小の操作回数です。
入力例 2Copy
20 2 5 1 2 7 7 4 5 3 7 7 4 5 5 5 4 6 5 6 1 6 1 2 7 7 4 5 7 7 4 5 5 5 4 6
出力例 2Copy
7
Score : points
Problem Statement
You are given an integer sequence of length . Additionally, its contiguous subsequences of lengths and are given: and .
You can perform the four operations on below any number of times (possibly zero) in any order.
- Add an arbitrary integer at the beginning of .
- Delete the element at the beginning of .
- Add an arbitrary integer at the end of .
- Delete the element at the end of .
Here, must be a non-empty contiguous subsequence of before and after each operation. Find the minimum total number of operations needed to make equal . Under the Constraints of this problem, it is guaranteed that one can always make equal by repeating operations.
What is a contiguous subsequence?
A sequence is a contiguous subsequence of when there is an integer satisfying such that for every .
Constraints
- and are contiguous subsequences of .
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
7 3 1 4 1 5 7 2 2 3 1 3 1 5 7
Sample Output 1Copy
3
You can make equal while keeping a non-empty contiguous subsequence of , as follows.
- First, delete the element at the beginning of . Now, you have .
- Next, add at the end of . Now, you have .
- Furthermore, add at the end of . Now, you have , which equal .
Here, you perform three operations, which is the fewest possible.
Sample Input 2Copy
20 2 5 1 2 7 7 4 5 3 7 7 4 5 5 5 4 6 5 6 1 6 1 2 7 7 4 5 7 7 4 5 5 5 4 6
Sample Output 2Copy
7