Codeforces Round 648 (Div. 2) 1365C - Rotation Matching Solution
Problem Link : https://codeforces.com/problemset/problem/1365/C
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- const int mx = 200009;
- int sh[mx + 1] ;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int n, x;
- cin >> n;
- int a[n + 1], b[n + 1];
- for (int i = 1; i <= n; i++) {
- cin >> x;
- a[x] = i;
- }
- for (int i = 1; i <= n; i++) {
- cin >> x;
- b[x] = i;
- }
- int c, ans = 0;
- for (int i = 1; i <= n; i++) {
- c = a[i] - b[i];
- if (c < 0) c += n;
- sh[c]++;
- ans = max(ans, sh[c]);
- }
- cout << ans << endl;
- }
No comments