Cod sursa(job #2841460)
| Utilizator | Data | 29 ianuarie 2022 19:17:39 | |
|---|---|---|---|
| Problema | PScPld | Scor | 80 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <bits/stdc++.h>
using namespace std;
ifstream in("pscpld.in");
ofstream out("pscpld.out");
string s,a;
int main()
{
ios_base::sync_with_stdio(false);
in.tie(0),out.tie(0);
in>>s; a="@#";
for(char c:s)
a+=c+string("#");
a+='$';
int l=0,r=-1;
int n=a.size()-2;
vector<int> p(n+2);
long long ans=0;
for(int i=1;i<=n;++i)
{
p[i]=max(0,min(r-i,p[l+r-i]));
while(a[i-p[i]]==a[i+p[i]])
++p[i];
if(i+p[i]>r)
l=i-p[i],r=i+p[i];
if(i>1 and i<n)
ans+=p[i]/2;
}
out<<ans<<'\n';
return 0;
}
