Codeforces648div2C
8181 단어 Codeforces
원제:
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let’s call them a and b.
Note that a permutation of n elements is a sequence of numbers a1,a2,…,an, in which every number from 1 to n appears exactly once.
The message can be decoded by an arrangement of sequence a and b, such that the number of matching pairs of elements between them is maximum. A pair of elements ai and bj is said to match if:
i=j, that is, they are at the same index. ai=bj His two disciples are allowed to perform the following operation any number of times:
choose a number k and cyclically shift one of the permutations to the left or right k times. A single cyclic shift to the left on any permutation c is an operation that sets c1:=c2,c2:=c3,…,cn:=c1 simultaneously. Likewise, a single cyclic shift to the right on any permutation c is an operation that sets c1:=cn,c2:=c1,…,cn:=cn−1 simultaneously.
Help Ishika and Hriday find the maximum number of pairs of elements that match after performing the operation any (possibly zero) number of times.
Input The first line of the input contains a single integer n (1≤n≤2⋅105) — the size of the arrays.
The second line contains n integers a1, a2, …, an (1≤ai≤n) — the elements of the first permutation.
The third line contains n integers b1, b2, …, bn (1≤bi≤n) — the elements of the second permutation.
Output Print the maximum number of matching pairs of elements after performing the above operations some (possibly zero) times.
Examples
사고방식: 모든 원소가 a와 b의 위치에 있는 차이를 기록하고 마지막으로 가장 많이 반복되는 것을 선택한다.
ACcodes
#include
using namespace std;
const int N = 2e5+10;
int visa[N]={0},visb[N]={0},e[N];
bool cmp(int a, int b)
{
return a>b;
}
int main()
{
int test=1;
//scanf("%d",&test);
while(test--) {
int n;cin>>n;
int a[N],b[N];
for(int i=0;i<n;i++)
cin>>a[i],visa[a[i]]=i,e[i]=0;
for(int i=0;i<n;i++)
cin>>b[i],visb[i]=visa[b[i]];
int res=0;
for(int i=0;i<n;i++)
{
res = max(res,++e[(visb[i]-i+n)%n]);
}
cout << res << endl;
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces 1287C Garland제목 링크:Codeforces 1287C Garland 사고방식: 우리기dp[i][j][0]와 dp[i][j][1]는 각각 i개가 홀수/짝수이고 앞의 i개 안에 j개의 짝수가 있는 상황에서 i개의 최소 복잡도.첫 번...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.