NC219808. Permutation
描述
输入描述
The first line contains an integer — the length of and .
The second line contains integers .
The third line contains integers .
It is guaranteed that and are both permutations.
输出描述
Output the minimum number of operations to make and the same.
示例1
输入:
5 5 2 3 4 1 5 3 2 1 4
输出:
3
说明:
For the first example, there is a possible way:C++(clang++11) 解法, 执行用时: 682ms, 内存消耗: 6532K, 提交时间: 2021-03-27 15:04:38
#include<iostream> #include<algorithm> using namespace std; int a[1000001],b[1000001]; int main(){ int n,c;cin>>n; for(int i=0;i<n;++i)cin>>c,a[c]=i; for(int i=0;i<n;++i){ cin>>c; if(a[c]-i>=0)b[a[c]-i]++; } int m=n; for(int i=0;i<n;++i)m=min(m,n-b[i]); cout<<m<<endl; return 0; }