Pagini recente » Cod sursa (job #2178584) | Cod sursa (job #934238) | Cod sursa (job #2564356) | Cod sursa (job #2245936) | Cod sursa (job #6581)
Cod sursa(job #6581)
#include <cstdio>
#include <string>
using namespace std;
const char iname[] = "pscpld.in";
const char oname[] = "pscpld.out";
#define MAX_N 1000007
char A[MAX_N];
int L[2 * MAX_N], N;
long long Res;
void read_in(void) {
freopen(iname, "r", stdin);
scanf("%s", A + 1);
N = int(strlen(A + 1));
}
int main(void) {
read_in();
for (int index = 1; index < N << 1; ++index) {
if ((index & 1) && (L[index] == 0))
L[index] = 1;
int li = index - L[index] - 1;
int ls = index + L[index] + 1;
if (index & 1) {
for (; (0 < li) && (ls < N << 1) && (A[li / 2 + 1] == A[ls / 2 + 1]); li -= 2, ls += 2) {
if ((L[ls - 1] == 0) || (L[ls - 1] > L[li + 1]))
L[ls - 1] = L[li + 1];
if ((L[ls] == 0) ||(L[ls] > L[li]))
L[ls] = L[li];
L[index] += 2;
}
} else {
for (; (0 < li) && (ls < N << 1) && (A[li / 2 + 1] == A[ls / 2 + 1]); li -= 2, ls += 2) {
if ((L[ls - 1] == 0) || (L[ls - 1] > L[li + 1]))
L[ls - 1] = L[li + 1];
if ((L[ls] == 0) ||(L[ls] > L[li]))
L[ls] = L[li];
L[index] += 2;
}
}
}
for (int index = 1; index < N << 1; ++index) {
if (index & 1)
Res += (long long) (L[index] / 2 + 1);
else
Res += (long long) (L[index] / 2);
}
freopen(oname, "w", stdout);
printf("%lld\n", Res);
return 0;
}