https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/08/Codeforces-Round-427-Div-2-problem-D-Palindromic-characteristics-Solution-In-CC1.png?fit=640%2C360

Codeforces Round #427 (Div. 2), problem: (D) Palindromic characteristics Solution In C/C++

#include <stdio.h>
#include <string.h>

#define N 5000

int main() {
static char cc[N];
static int dp[N][N], kk[N + 1];
int n, i, j;

scanf(“%s”, cc);
n = strlen(cc);
for (i = 0; i < n; i++) {
dp[i][i] = 1;
if (i + 1 < n && cc[i] == cc[i + 1])
dp[i][i + 1] = 2;
}
for (i = n – 1; i >= 0; i–)
for (j = i + 2; j < n; j++)
if (dp[i + 1][j – 1] > 0 && cc[i] == cc[j])
dp[i][j] = dp[i][(i + j – 1) / 2] + 1;
for (i = 0; i < n; i++)
for (j = i; j < n; j++)
kk[dp[i][j]]++;
for (i = n – 1; i >= 1; i–)
kk[i] += kk[i + 1];
for (i = 1; i <= n; i++)
printf(“%d “, kk[i]);
printf(“\n”);
return 0;
}

(Visited 11 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: