Codeforces Round 648 (Div. 2) 1365C - Rotation Matching Solution


 

Problem Link : https://codeforces.com/problemset/problem/1365/C

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  7. #include <bits/stdc++.h>
  8. using namespace std;
  9. const int mx = 200009;
  10. int sh[mx + 1] ;
  11. int32_t main() {
  12. ios_base::sync_with_stdio(0);
  13. cin.tie(0);
  14. int n, x;
  15. cin >> n;
  16. int a[n + 1], b[n + 1];
  17. for (int i = 1; i <= n; i++) {
  18. cin >> x;
  19. a[x] = i;
  20. }
  21. for (int i = 1; i <= n; i++) {
  22. cin >> x;
  23. b[x] = i;
  24. }
  25. int c, ans = 0;
  26. for (int i = 1; i <= n; i++) {
  27. c = a[i] - b[i];
  28. if (c < 0) c += n;
  29. sh[c]++;
  30. ans = max(ans, sh[c]);
  31. }
  32. cout << ans << endl;
  33. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.