Cod sursa(job #2960882)

Utilizator MihaiCostacheCostache Mihai MihaiCostache Data 5 ianuarie 2023 10:29:11
Problema PScPld Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <bits/stdc++.h>

using namespace std;
ifstream fin("pscpld.in");
ofstream fout("pscpld.out");
string s, aux;
int p[2000002], n;
int main()
{
    fin>>s;
    aux="*";
    for(int i=0; i<s.size(); i++)
    {
        aux+="*";
        aux+=s[i];
    }
    aux+="*";
    s=aux;
    n=s.size()-2;
    int st, dr;
    st=dr=1;
    for(int i=1; i<=n; i++)
    {
        if(dr>i)
        {
            p[i]=min(dr-i, p[st+dr-i]);
        }
        else
            p[i]=0;
        while(s[i+p[i]]==s[i-p[i]])
        {
            p[i]++;
        }
        if(i+p[i]>dr)
        {
            dr=i+p[i];
            st=i-p[i];
        }
    }
    int sol=0;
    for(int i=1; i<=n; i++)
    {
        sol+=p[i]/2;
    }
    fout<<sol;
    return 0;
}