Iamtui1010

paliny

Nov 7th, 2021
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. //#include<bits/stdc++.h>
  2. #include<iostream>
  3. #include<fstream>
  4. #include<vector>
  5. #include<string>
  6.  
  7. #define long long long
  8. #define nln '\n'
  9.  
  10. using namespace std;
  11.  
  12. // GLobal variables: f1, f2,
  13.  
  14. fstream f1,f2;
  15.  
  16. inline void openf()
  17. {
  18.     f1.open("paliny.inp", ios:: in);
  19.     f2.open("paliny.out", ios:: out);
  20. }
  21.  
  22. inline void closef()
  23. {
  24.     f1.close();
  25.     f2.close();
  26. }
  27.  
  28. long n;
  29. string str;
  30.  
  31. void data()
  32. {
  33.     f1.tie(0)->sync_with_stdio(0);
  34.     f2.tie(0)->sync_with_stdio(0);
  35.     cin >> n;
  36.     cin >> str;
  37. }
  38. long mav = -1e9;
  39.  
  40. void browse(long i, long j)
  41. {
  42.     long cou;
  43.     if (i != j)
  44.         cou = 0;
  45.     else
  46.         cou = -1;
  47.  
  48.     long lef = i, rig = j;
  49.     while (lef >= 0 && rig < n && str[lef] == str[rig])
  50.     {
  51.         cou += 2;
  52.         --lef; ++rig;
  53.     }
  54.     if (cou > mav)
  55.         mav = cou;
  56. }
  57.  
  58. void process()
  59. {
  60.     long i = n/2, j = n/2 + 1;
  61.     while (i > mav/2 && j < n - mav/2)
  62.     {
  63.         //cout << i << " - " << j << nln;
  64.         browse(i, i);
  65.         browse(i-1, i);
  66.         browse(j, j);
  67.         browse(j, j+1);
  68.         --i;
  69.         ++j;
  70.         //cout << "mav: " << mav << nln;
  71.     }
  72. }
  73.  
  74. void view()
  75. {
  76.     cout << mav << nln;
  77. }
  78.  
  79. int main()
  80. {
  81.     openf();
  82.     data();
  83.     process();
  84.     view();
  85.     closef();
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment