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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.