Pagini recente » Cod sursa (job #1926465) | Cod sursa (job #2760667) | Cod sursa (job #1441392) | Cod sursa (job #2678741) | Cod sursa (job #2942040)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream cin("pscpld.in");
ofstream cout("pscpld.out");
int t[2000001];
signed main() {
string s;
char ch;
int i, drmax, curCenter, lung, rez;
drmax = 0;
curCenter = 0;
while(cin>>ch) {
s = s + '#' + ch;
}
s = s + '#';
lung = s.size() - 1;
for (i = 1; i <= lung; i++) {
if (i <= curCenter + t[curCenter]) {
t[i] = min(t[2 * curCenter - i], curCenter + t[curCenter] - i);
}
else {
t[0] = 0;
}
while (i + t[i] + 1 <= lung && i - t[i] - 1 >= 0 && s[i - t[i] - 1] == s[i + t[i] + 1]) {
t[i]++;
}
if (i + t[i] > curCenter + t[curCenter]) {
curCenter = i;
}
}
rez = 0;
for (i = 1; i <= lung; i++) {
if (i % 2 == 1) {
rez = rez + t[i] / 2 + 1;
}
else {
rez = rez + t[i] / 2;
}
}
cout << rez;
return 0;
}