Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include<bits/stdc++.h>
- #include<iostream>
- #include<fstream>
- #include<vector>
- #include<string>
- #define long long long
- #define nln '\n'
- using namespace std;
- // GLobal variables: f1, f2,
- fstream f1,f2;
- inline void openf()
- {
- f1.open("paliny.inp", ios:: in);
- f2.open("paliny.out", ios:: out);
- }
- inline void closef()
- {
- f1.close();
- f2.close();
- }
- long n;
- string str;
- void data()
- {
- f1.tie(0)->sync_with_stdio(0);
- f2.tie(0)->sync_with_stdio(0);
- cin >> n;
- cin >> str;
- }
- long mav = -1e9;
- void browse(long i, long j)
- {
- long cou;
- if (i != j)
- cou = 0;
- else
- cou = -1;
- long lef = i, rig = j;
- while (lef >= 0 && rig < n && str[lef] == str[rig])
- {
- cou += 2;
- --lef; ++rig;
- }
- if (cou > mav)
- mav = cou;
- }
- void process()
- {
- long i = n/2, j = n/2 + 1;
- while (i > mav/2 && j < n - mav/2)
- {
- //cout << i << " - " << j << nln;
- browse(i, i);
- browse(i-1, i);
- browse(j, j);
- browse(j, j+1);
- --i;
- ++j;
- //cout << "mav: " << mav << nln;
- }
- }
- void view()
- {
- cout << mav << nln;
- }
- int main()
- {
- openf();
- data();
- process();
- view();
- closef();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment