Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <string>
- #include <stack>
- #include <set>
- #include <map>
- #define pii pair <int,int>
- #define vec vector
- using namespace std;
- using ll = long long;
- using ld = long double;
- using db = double;
- void cv(vector <int> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvl(vector <ll> &v){
- for (auto x: v) cout<<x<<' ';
- cout<<"\n";
- }
- void cvv(vector <vector <int> > &v){
- for (auto x: v) cv(x);
- cout<<"\n";
- }
- int n,why;
- vector <int> S;
- string som;
- vector <int> ans;
- vector <int> m;
- int cnt=0;
- void mnk(){
- n = S.size();
- m.resize(n,0);
- //cout<<"S\n";
- //cv(S);
- pii lr = {-1, -1};
- pii now;
- for (int i = 0; i < n;++i){
- int l = lr.first, r = lr.second;
- if (i >= l && i <= r){
- int idx = l + (r - i);
- m[i] = min(r - i + 1, m[idx]);
- }
- while (i - m[i] >= 0 && i + m[i] < n && S[i - m[i]] == S[i + m[i]]){
- ++m[i];
- }
- now = {i - m[i] + 1, i + m[i] - 1};
- if (now.second > lr.second){
- lr = now;
- }
- }
- for (int i = 0;i<som.size();++i){
- //cout<<som[i]<<" "<<'#'<<' ';
- }
- //cout<<"\n";
- //cout<<"S m\n";
- //cv(S);
- //cv(m);
- for (int i = 0; i < n;++i){
- if (m[i] != 0){
- m[i]--;
- }
- cnt += m[i] / 2;
- }
- }
- int main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- //cin>>n>>why;
- /*S = {0};
- for (int i=0;i<n;++i) {
- int x;
- cin>>x;
- S.push_back(x);
- S.push_back(0);
- }
- mnk();
- sort(ans.begin(), ans.end());
- //cout<<"ans\n";
- cv(ans);*/
- //int x = 'a' - 96;
- //cout<<x<<"\n";
- cin>>som;
- S = {0};
- for (int i = 0;i<som.size();++i){
- int d = som[i] - 96;
- // cout<<"i = "<<i<<"\n";
- //cout<<"som[i] = "<<som[i]<<"\n";
- //cout<<"d = "<<d<<"\n\n";
- S.push_back(d);
- S.push_back(0);
- }
- //cout<<"S\n";
- //cv(S);
- mnk();
- cout<<cnt;
- }
- /*
- 6 2
- 1 1 2 2 1 1
- abcbaceedeeakaee
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement